« first day (9 days earlier)      last day (4932 days later) » 

3:00 PM
Tomaka17, 2010 supports some of it now. My guess is a service pack for 2010 will provide further features.
 
lx
well, afaik they haven't said anything about that.
so, we have to wait and see...
 
META: The user list of this chatroom is very ugly for me (Firefox 3.6.11, Win 7). What about you?
 
Can't wait for variadic templates and default values for class members
 
lx
@notinlist: same FF & win7: have no problems
can't wait for multithreading ;)
 
ff4.06b, win7: ff is still quite buggy but the list displays ok
 
3:02 PM
@lx yeah I'm using boost as a replacement for <thread>, this is killing my compilation time
 
lx
@tomaka: until now, my boss won't let me program in c++ (only in c)"since no one understands it". since we have to do a lot of platformindependent stuff, "native" MT is a killer argument for me as c++ supporter ;)
 
@ix I sympathize with you and employers who fear change. It's rough.
 
so, onboard threads will make it simplier?
 
It will make it standard.
 
@lx: C++ would be better for cross-platform if the ABI was standardized. But that will probably never happen. As for your boss' perception that "no one understands it", he is wrong :)
 
3:08 PM
Standard AND simplier than if you use the Win32 or POSIX API
 
Aha
@Mads So, you dare.. :)
 
@mlvljr: Dare what? :)
 
lx
@Mads: Well, at least he doesn't ;)
 
He who? :))
 
lx
my employeer
 
3:10 PM
@ix does he code? if not, then why does it matter? if so, then why doesn't he educate himself?
 
:)))))
 
lx
yes he does
well... had a few arguments about that already.
looking forward to 0x, maybe then I'll convert some oppinions ;)
 
I'm already using a lot of lambda-intensive code
 
lx
<3 lambdas
 
I would cry if I had to code in C++03
 
3:12 PM
I'm pretty convinced that one can avoid 90% of all the C++ wtfness by simply avoiding template magic/template abuse. And by using static and dynamic asserts generously.
 
lx
just having not to write helper classes for stuff like std::sort makes them awesome ;)
 
I think templates will unleash their full potential with concepts and modules in C++16 :)
 
no way to do cleverer things without thinking cleverer
; sad..
 
Hi folks
 
Sadly, not abusing templates, and using a lot of asserts doesn't make my code more readable :\
 
lx
3:15 PM
@Mads: Well, C++ has some implicit pitfalls (like.. say... compiler generated copy constructurs + pointer variable as class member + destructor delete), which can cause you some severe headaches if you don't know them.
But once you know them, they don't kill you any more.
 
@lx: Sure, I agree with that.
 
Has anyone here ever released an open-source project ? What should I check before tagging my first version ?
 
I think what I dislike the most with C and C++ are the implicit conversions. That's the one feature that has caused me the most trouble.
 
lx
Ah yes... true. You are definitely not alone ;)
 
Linker errors cause me the most trouble atm
 
3:18 PM
Always make your single-parameter constructors explicit, or you are going to get burned.
 
lx
@ereOn: Hm... check if you have the right license header in every file.
I don't know if that's a real requirement though :\ But at least in seems to be a common practice.
 
Have we got an OS chat on SO? :))
 
/me is trying to think of what causes him the most trouble
 
@Tony: That's a symptom not the cause.
 
lx
@mlvljr yes, there is one
 
3:19 PM
@lx: Already done ;) Thx.
 
@MadsElvheim I like to make my multiple-parameters constructors explicit too, just for the principle
 
Typo's tend to cause me the most trouble... or small hard-to-notice logic errors
 
@CiscoIPPhone if only I'd find what the cause was grrrr
 
@Mads: I would disagree on the always make your single-parameter constructor explicit thing
 
my biggest issue is coworkers not understanding that const is their friend
 
3:20 PM
Often it cause trouble yes, but sometimes, it makes sense
@krousey: you're not alone.
@krousey: Mine don't understand the need for namespaces as well...
 
@ereOn: Can you give me an example where it would be a good idea to not make a single-parameter constructor explicit?
 
lx
or the need for naming variables something other then "param1","param2"...
 
@MadsElvheim class FixedPointNumber { public: FixedPointNumber(double); };
 
@mads Class BigInt;
 
@Mads sure: if just implemented this afternoon a library to deal with memcached servers
 
3:22 PM
90% of the time though, I would agree with mads
 
@Mads: memcached takes keys for its values which are strings
@Mads: In the first version I just used std::string for those. But suddenly, a requirement was added : the key should be transparently prefixed
So I created a Key class, which basically contains only a std::string
 
what does that mean?
 
but offers a way of decorating, undecorating the underlying key
 
ahh the key should be prepended with so text?
 
I think that a general rule would be: if the source and destination types are semantically equivalent, you can allow implicit conversion
 
3:24 PM
some*
 
this Key class has an implicit constructor from std::string (and another one from const char* actually)
But perhaps you see something wrong in this design ?
@Tomaka17: I agree.
 
is this called prefixing??
cant get it
 
@CiscoIPPhone: Yes. It's a prefix.
 
aha, thanks
 
lx
3:26 PM
so.. "something you put in front of a word"
 
i knew that
 
I'm not a native english speaker but I did not know "prefix" was such an uncommon word oO
 
damn it i'm neither
 
@Tomaka17: Yes, that makes sense. My problem with implicit conversion usually happens when you have: class Foo{ Foo(const A&); }; and A's constructor can take a type B. Then Foos can be constructed silently from B objects through A constructors.
 
lx
@ereOn: i don't think it is.
since it's latin based it should appear in a lot of languages
 
3:28 PM
@MadsElvheim Why is that a problem if A and B are semantically equivalent?
 
@lx: Yep, indeed. Its "préfixe" in french.
 
is it all about Key key1("my_app_prefix_blah"), key2("my_app_prefix_blah_blah"); ?
 
very new to C++., what is a vector?
 
Its an "array"
 
@Tomaka17: I didn't say they were. I agree with your sentiment.
 
3:29 PM
sort-of
 
std::vector is a container class like a resizeable array
 
that as some guarantees regarding direct access to elements
 
such as they are contiguous in memory
 
will that reset everytime i use that in a loop?
 
lx
@ereOn: in german i'd be "präfix" ;)
 
3:30 PM
stop it!
 
a vector in a loop?
 
:))
 
@lx: I live 2 km from Germany, but I didn't know that one ;)
(My german is so poor :/)
 
lx
@tomaka: "in-explicit" constructors allow for some nasty syntax too
 
@ereOn You live in Strasbourg? :o
 
3:30 PM
@Onnesh: I'm not sure what your question is.
 
lx
@ereOn: well.. my french is non-existent so ... ;)
 
@Tomaka17: Indeed
 
@Onnesh: Depends on what you mean with reset. Vectors follow normal scope rules.
 
@ereOn I live in bas-rhin too =)
 
ok, getting some values from DB but looks like its gettin reset in the loop, should diggin
 
3:32 PM
About STL containers... I wondered why they didn't do an even more generic container
 
@Tomaka17: Haha great ! ;)
 
For example: std::array<DYNAMIC> would be equivalent to a vector
 
lx
well, in c++ 0x there will be a std::array
 
A std::array<BTREE_WITh_KEYS> would be a map
 
@Tomaka17: I guess it would be too close from raw C arrays
 
lx
3:32 PM
not sure what you mean exactly though
 
No I mean a template<enum ContainerType> class Array; which is specialized for each value of ContainerType
 
lx
hehe, a policy based container?
 
More or less yes
 
@Tomaka17: I think you can generalize that by making your own allocator.
 
will catch later thanks
 
lx
3:33 PM
std::container<int, btree>
 
Yes, indeed.
 
That would be nicer than having five or six different classes
 
Not sure if the allocator interface allows for optimization though, when you use an array of constant size for storage.
 
@Mads: Good point.
@Tomaka17: Why would you prefer this ?
 
@ereOn: it's more generic =)
 
3:35 PM
:p
 
@Tomaka17: Maybe some of the containers from EASTL might please you: open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html
 
@Tomaka17 because the STL was published in ~95
 
lx
and replace int with var<numeric, no-float, signed>?
 
Haha good point (for @lx and @RogerPate)
 
@lx: Too much genericity kills the genericity
 
lx
3:37 PM
definitely ;)
 
(Haha, I love how you can edit your own chat posts)
 
lx
I just wanted to tag along. Still not sure if an insanely generic container was a joke or not ;)
 
Can someone tell me if RedHat Linux as a deprecated version of boost or if my sysadmin is just lazy ?
 
@lx: I wasn't joking in fact, that was just an idea I had last day and I wondered why they didn't do so since all the containers have similar functions
 
#define BOOST_VERSION="1_33_0"
:/
 
lx
3:40 PM
I can't really see the benefit of having an absurdly generic container and instead of.. say .. `map<T>` i have to write `container<T, red_black_tree, dynamic, standard-allocator, allow_[]_syntax>` (yes, that's a bit exaggerated)
or having a typedef, which would make it all the same ;)
 
I agree with @lx on this point.
 
@lx: map is little more than a template typedef in most implementations, fwiw
of course it's not quite that simple since c++ doesn't/didn't allow those, but that's the essence
 
lx
nods
 
Well, EASTL actually implements some fairly interesting containers, though no very general ones. For example containers that use fixed storage, non-instrusive lists where you provide the storage, etc.
I'll use it for my embedded stuff as soon as I get my C++ linker script to work again..
Not sure what's the easiest approach yet. Make a bootstrap with an ELF loader, or fight against GNU ld/objcopy and get the sections preserved in a flat binary.
 
You have to be very courageous to fight with ld/objcopy
That's like using autoconf/automake
 
3:46 PM
@Tomaka17: I've done it successfully before for the Gameboy Advance. But I don't quite remember what I did.
That is, weak symbols worked (globals), and constructors/destructors worked.
Oh, I started an OpenGL chat channel by the way :-)
 
chat chat chat all day long chat chat chat while i sing this song
 
lx
hm, the song seems to be over...
 
If C++ only has 14 users, I don't know how many will go on OpenGL
 
Gotta go. Cya.
 
lx
@ereOn: bye!
 
3:51 PM
Bye
 
@Tomaka17: I don't know either. StackOverflow's OpenGL base seems mostly to consist of homework-people.
Hopefully I'm wrong.
 
I don't check the OpenGL questions often on stackoverflow.com, but I don't remember seeing an interesting one for a while
 
A question... if i allocated any array of structure
like
struct teststruct{
int i;
A question... if i allocated any array of structure
like
struct teststruct{
int i;
int j:
}

teststruct *ts = new teststruct[10];
delete ts; // will it create any issue
// delete [] ts;
 
@Kasma that is UB, anything may happen
you cannot use delete on a pointer you got from new[], you must use delete[] instead
 
bt will memory be freed or not... i m bit confused... i know if struct has any pointer then it can cause issue
 
3:56 PM
nobody knows — anything can happen
 
bt if only POD datatype is there ... can't it will be free
 
stop trying to rely on Undefined Behavior
use delete[] when you new[] — or better yet, use a vector
 
okie... it means i need to change it everyplace... no actually it very old code , during devpartner i observed these issue .... most of them are
 
@Kasma A good programming practice is that you should destroy objects at the place where you created them
 
like char * str = new char[50]; delete str;
 
3:58 PM
@Tomaka17 much less relevant in c++
 
Not knowing whether your int* is an array or not means that you have a problem in your design
 
A better programming practice in C++ is to use resource acquisition is initialization (RAII) and not free resources yourself.
 
good c++ sticks resources in manager classes (such as smart pointers) asap, and when you do that, you explicitly have different places for creation and destruction
 
yeah i agree with u, just verifying old code with devpartner
 
@JamesMcNellis: SBRM :)
 
3:59 PM
@JamesMcNellis , @RogerPate Of course, but I was referring to the usage of new/delete
 
Yeah yeah yeah yeah
 
also char * str = new char[50]; delete str;
devpartner shows me error as memory conflicit
is it correct ??
 
No.
It needs to be delete[] str;
 
@Kasma: that mixes new[] and delete again; don't do that
 
okie... NOw i need change it several places ... yeah in new code we generally avoid these things
tnx guys :)
 
Zuu
4:02 PM
I was wondering if anyone know about the C++0x attributes, and how they will affect mangling (if at all) ?
 
I believe current thought is they won't participate in mangling
some people want them to merely provide hints without changing semantics, and in that case they definitely wouldn't affect mangling
I don't think it's been completely settled yet
 
Zuu
I see
That might explain why it's hard to find anything about
 
committee papers and a handful of blogs would be where I'd look
 
Zuu
I did get the impression from various places, that these attributes will all be hardcoded into the compilers. As opposed to allowing people to defined their own attributes. Is that the case (so far)?
 
I read something about that, but didn't look into it more
attributes just haven't interested me (yet?)
 
4:08 PM
I think attributes are like GCC's __attribute__ or #pragma
 
Zuu
Ah!
 
Meaning they are hardcoded in the compiler, but the compiler will ignore an unknown attribute
 
looks like the last mailings about them was feb-mar
 
That's the difference between an attribute and a keyword
 
well, there's supposed to be special syntax for attributes, so they wouldn't have a keyword's global uniqueness
 
Zuu
4:11 PM
Roger Pate, That's a nice source of 'stuffs' :D
 
@RogerPate What I mean is that if you write void f [[noreturn]] (); it's different than void f noreturn (); (ie. keyword) because the compiler would generate an error if it doesn't know noreturn in the second case, and not in the former
Note that I'm not sure about the location of the attribute, I don't know if it's in front of the declaration, before the name, etc.
 
Zuu
from everything i've seen it's in front, or behind the parameters on functions
 
I'm not sure but I think they changed the location in the latest draft
 
Zuu
Just to make sure i understand this source that Roger Pate linked (the feb-mar link). This mailing list contains the working drafts and changes of the C++0x standard, right?
As in, all these .pdf's and their highlighted changes are all aiming towards a final C++0x standard?
 
Yes
 
Zuu
4:22 PM
Nice!
 
N3126 is currently the latest draft.
 
But most of their discussions are about small details, not very interesting to read
 
@Tomaka17: There are funny jokes in the drafts.
 
Zuu
Well, im working on my own language, albeit quite unlike C++ but still has a lot in common. Im sure i'll find lots of interresting stuff in those documents :)
 
N3035 changed the definition of "ill-formed program" to "a wannabe C++ program"
2
 
4:25 PM
Haha
 
I think it was N3092 where there was a footnote explaining that "atomic objects are neither active nor radioactive."
It looks like Canada objected to that and it was removed from N3126. :(
 
Blame Canada?
 
Ha ha; Canada also objected to "Among other implications, atomic variables shall not decay."
 
Never been to any C++ chat before this one o_o
 
Zuu
I think it's awesome that they slap stuff like that, into an otherwise very technial and dry text :)
 
4:31 PM
C++ jokes: saying that atomic objects shall not decay
 
@Zuu Yeah, that's cool, still I don't thing C++ is the right thing to "chat about" :))
 
Zuu
there should be a t least one joke on every other page, that would motivate people to actually read these documents
Anyways, thank you guys for some input on these soon-to-be attributes! I think i'll go look through these documents to see if i can get some inspiration.
 
@Zuu working drafts contain the editing history from the previous working draft, the FCD doesn't have that (there is a WD corresponding to the FCD too)
 
Zuu
@RogerPate I don't think i understood what you just said.
 
@Zuu: If you download one of the working drafts, you'll see green highlighted text and red highlighted and struck out text, indicating additions and removals from the previous draft.
The Final Committee Draft (FCD) (N3092) doesn't have those because it's a formal document.
 
4:42 PM
Does someone know under which circumstances std::list iterators can become invalid after insertion operation?
 
There is a corresponding working draft though (N3090, I think) that has the modifications from N3035, which was the previous working draft.
 
Zuu
Hmmmm... i've just been looking through the most recent (N3126, I've actually looked at that before), and i have yet to see any highlighted text in it.
 
@Zuu: There aren't a lot of changes since they're trying to stabilize the document. If you search for "radioactive," you'll find the removed comment to which I referred earlier.
 
Zuu
Ah i see it! :D
 
@HardCoder1986: Never. Insertion and erasure from a std::list do not affect iterators, except that when you erase an element, iterators to it are invalidated, obviously.
 
4:45 PM
What about iterators pointing to the node erased?
 
Zuu
Ok so what Roger Pate tried to tell me, is that there are FCD's that doenst have highlights in them. Good good :)
 
There is only one FCD
 
though someone was saying it's allowed to have more than one FCD, wg21 just hasn't (yet)
 
@RogerPate Yeah; if things go poorly and they have to add or remove major features, another FCD might have to be issued, delaying standardization another year.
 
One entire year? That looks a bit bureaucratic
 
4:54 PM
Hello every one, lets have a cheer for VS2010 visualisation and modelling pack
big boo for the fact that by default it only supports c#
any one know of where I can get the T4 templates for c++?
I assume some one must have made them for download by now
 
a bit bureaucratic? have you seen the ISO process?
 
Hum I'm not familiar with the standardization process, but I guess it must be horrible
 
any one care for visual studio at all?
 
what's visual studio? can I apt-get install it?
 
¬_¬
can just about bring my self to laugh at the one
it may be lazy, but dam it I want UML to code stubs done for me!
 
5:08 PM
I've never found that kind of code generation really useful
 
you mean, you've never found letting the IDE turn the UML diagrams that you need to do any way into a starting point useful?
 
I need to do uml diagrams anyway?
 
sure it don't take that much time to write the code, but its a dam sight faster then I could do it
and having them done from you code is not useful?
 
I used Rational Rose RT on a large project for two years; it turned UML into code. I've vowed never to use model-driven development again.
 
so what was so wrong with model-driven then? I assume your tool let a functions directly into the code, then update your digrams...
 
5:15 PM
It was unmanagable. It made it too difficult to make quick changes to code. It made it too difficult to navigate the code. It was impossible to diff changes to the code. IT was near impossible to debug the code.
I can look at a 1,000 line source file and if it's well written, I can figure out what it's doing and get up to speed with it in a very short span of time. When you have crazy UML diagrams and little pieces of code here and there, it's near impossible to actually understand what is going on.
 
Then in my opinion your tool was broken. The VS Visualisation and modelling tool, at least for c# just make stubs for you. It is up to you still to actually implement the code
I can see how it would be a pain the ass if you had to edit the code through the UML diagram, but VS will generate the code files for you to then go and edit
And you can happily make UML diagrams for documentation from the code
 
It was broken. I don't disagree with that. I've never used the V&M pack, and it may be very good.
 
I may be being blind here, but how is that not anything but helpful
 
Even so, UML is really, really, really overrated.
5
 
it would be, except it doesn't come with C++ templaters for the code generation
UML probably is, but when you rae being asked to provide class diagrams for your code letting them be done for you is WIN in my eyes
 
gcc
5:24 PM
hey guys , I want start to learn c ++ and data structure , can any one recommend book , n which I find everything
 
everything? in one book?
you should be a mussel man if you can carry it
 
gcc
everything about c++
 
oh sure, now it decides to post that; duplicate chat messages plague me like locusts
 
@gcc : if you want to learn C++ you should first change your nickname to g++ ;)
 
Wow, still lots of people.
 
5:40 PM
you can always join the room I started, still plenty of peace and quiet

Tags

Tag, you're it!
 
@GMan: I think it's ironic that you loves the lowercase/underscore, but you use PascalCasing for your name.
 
he's gman in code!
 
@James Ha, true. Even more ironic, I'm very anal about the spelling of my name. "Gman" drives me nuts.
 
5:53 PM
That's maybe a stupid question but... when you use a create a lambda which copies the local variables (like in auto f = [=](int) { }) does it copy all the local variables or only the ones used in the body of the lambda ?
 
I'm not sure; I suspect only those used
 
Good question. I suspect it's strictly suppose to be, but the as-if rule lets an optimizer only copy the ones used.
to be allof them*
 
Ok thanks
 
you could create a contrived situation that observed the copies, even if the lambda doesn't directly reference them
 
A lambda is supposed to copy only the one used
 
5:56 PM
@Tomaka17 Only variables that are used are copied.
 
Ok ok
 
capturing the whole stack [=] or [&] is problematic in my opinion and really only good for slides, not real code.
 
or short functions where you really do want the whole scope
 
I find this little syntax a bit too limited, I would like to write [this->something] instead of [this] and then use something inside the body
Especially in cases where this->something is a shared_ptr that can be safely copied, which is not the case for this
 
Why not [something]?
 
5:59 PM
auto something = this->something; [=something]{...
 
@GMan That's forbidden (or at least it doesn't compile so I guess it's forbidden)
@RogerPate Yeah that's what I do, but it's not so convenient
 
Oh, that's silly. Why is it forbidden?
 
but it is explicit
@GMan: how should item be captured, given [item]?
 
What do you mean?
 
perhaps I misunderstood what you meant by [something]
 
6:03 PM
I also would like to use move-constructing in the lambda, something like [std::move(foo)]
 
@GMan: You can only capture variables with automatic storage duration and this, IIRC
 
What's the rationale behind that? Couldn't of it been easily made that [something] looks up something as usual, and does auto something = this->something; [=something]{...?
or rather auto __x = x; /* lookup x */; [=__x]{ for some variable x.
 
the rationale is it's untested, no implementation, of less use, potentially confusing, and it can be added later; in other words, your grandkids might see it
 
its much easier to add a feature later than to deprecate it
 
Ha, alright. Wish they updated more often.
 
6:07 PM
me too
 
@Rick hey, at least they got rid of export!
 
yeah :)
 
It's a shame they can't be more ballsy with deprecation, now that you mentioned it.
 
They could deprecate raw arrays, and replace them with an implementation-defined std::array ;) (ok that's a bit too extreme)
 
agree. even flagging things for deprecation would be nice.
 
6:09 PM
nah, give all string literals a std::basic_string type
 
Or just more ballsy in general, heh. I hate decltype, it's such an ugly name. :( typeof would be much nicer, but we can't step on non-standard code for some reason... (was the rationale I heard). And dammit drop register as a keyword so I can finally name a function register(...).
 
#define decltype type_of
 
compatibility with c and existing compilers/tools is an important concern for the committee, and with good reason: 10 years between standards is too long
 
I hated decltype when I first saw it, I guess I'm just used to it.
 
At least they deprecated register in 0x. @Roger Yeah :/ Is it a myth that it has to be at least 10 years, or is that just how it ends up?
@Rick Yeah I'm used to it now too.
 
6:15 PM
Do you use decltype much? I don't unless I need the type of a lambda for a template or in macros / static asserts
 
I've only used it here or there, usually around meta-programming. Let me search for fun.
 
@GMan: it must be 10 years according to ISO's process; updates and reports (TC1, TR1) are allowed
 
That's so :/
 
but they can't/shouldn't/mustn't/shant/whatever make drastic changes
 
So in one of my projects, I use it in an is_functor class, has_member class, and in other places when I just want the type of some function, to minimize repetition.
 
6:21 PM
is_functor and has_member are the kind of classes that are missing in <type_traits>
 
afaik, yeah.
 
You get is_standard_layout or add_volatile but no is_callable or remove_member_pointer
Which I'd say are more useful
 
@GMan that about matches my usage, I have it in a static_assert or two as well
 
Yeah, I've got a few of those in there.
several
@Tomaka17 Agreed.
Hehe, Alf always puts "Cheers & hth.,". Aren't we suppose to edit that out? :P
 
6:38 PM
@GMan I'm OCD about editing that crap out :(
 
@GMan Yes, but if you edit it out you have to tell him to stop being so freakin friendly.
 
I know, haha. That's why I don't want to. I'd feel bad.
 
link me, I won't feel bad
 
I don't go looking for it, otherwise I'd go crazy, but when I'm already there... :)
 
6:40 PM
lol
Isn't there a cleaner way to attain the same result as my comment here? I can't remember.
I'm soooooo dumb, ignore that.
 
if 10k could see deleted comments, it's be worth all the time invested :P
 
:]
 
Could somebody tell me the correct way to clean up a vector of pointers?
 
The correct way is to use a vector<shared_ptr<T> > (or unique_ptr or some other smart pointer) and take advantage of automated cleanup.
 
I've got:
while(! objects.empty())
   {
      delete objects.back();
      objects.pop_back();
   }
 
6:48 PM
(Or a Boost Pointer Container)
 
@Bocochoco Is that in a destructor?
 
No, its at the end of my main function.
before return 0;
 
By doing so you don't use the strength of C++
 
@Tomaka17, How would you suggest I clean it up?
 
As JamesMcNellis said, you should use a vector<shared_ptr<T>> or vector<unique_ptr<T>>
And the objects will be destroyed automatically
 
6:53 PM
I've never seen those before. :/
 
Instead of calling objects.push_back(new T) you call objects.push_back(make_shared<T>()) or objects.push_back(unique_ptr<T>(new T))
 
@Bocochoco The idea here is that things clean up after themselves. This requires you follow the SRP. That is, a class or function should do one thing. As it stands, you've broken the rule because you're both managing and using a resource in main.
 
40
Q: What is a smart pointer and when should I use one?

Alex ReynoldsWhat is a smart pointer and when should I use one?

2
 
That resource needs to manage itself.
So at the least, you need to make a ptr_vector class that internally has a vector of pointers, and in the destructor it runs the code you posted. Now you can use the ptr_vector class, and it manages the resources, automatically.
Another route is to use a smart pointer in a vanilla std::vector, and each element cleans up after itself.
A subtle difference; that route is probably easiest once you have a smart pointer at your disposal.
 
Interesting.
 
6:56 PM
Or maybe even simply use vector<T> instead of vector<T*> ; that's a mistake I made when I was a beginner, I was using pointers when I didn't need to
But that's another topic
 
@Tomaka17 Brings up a good point too; typically you want to avoid dynamic allocation as much as possible.
 
guys, i want some attention to my question on stackoverflow, is it against the chat rules? :)
 
@Anton Probably not, but you did a nice job of sneaking it in anyway. ;)
 
Are there rules on chat?
 
See the FAQ.
 
6:59 PM
Well, let me try, i dont see anything about it in faq :) can you please help me with this: stackoverflow.com/questions/4013045/… ? I'd really appreciate any help
 
@James @RogerPate See a better way to do this? Seems too ugly.
 
Heh. Perhaps I don't need a vector of pointers. If I have vector<t> v; populated, and I depopulate it in a while loop using v.pop_back();, it cleans up after itself?
 

« first day (9 days earlier)      last day (4932 days later) »