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

19:00
@Bocochoco If you have a std::vector<T>, when the vector ends its lifetime, it takes the objects with it. You don't have to do anything.
@Gman, Thank you :)
That's the point of destructors; they allow a class to manage its internal resources in a guaranteed, consistent manner. So you just use the vector. No prob.
@Anton Is there a reason you're doing (*it). and not it->?
It'll look cleaner.
The only thing I'm concerned about is whether or not multiple calls to objects.push_back(object(0, "A")); will cause a problem. object being a class I've made.
user466534
can anybody explain me can i use two dimensional list in c++?P because list is like a linked list structure
@Gman how do you do that?
I mean
A vector<T>
myVector.add( new T() ) ?
19:04
wat
myVector.push_back(T())
just T() ?
T t; myVector.push_back(t);
@Bocochoco The only requirement is that your class must be copy-constructible or move-constructible
@CiscoIPPhon doesn't that cause you to have a myVector with a bunch of variables from the stack?
19:06
what does move-constructible mean?
( confession: I'm still in the process of switching from C to C++ )
i heard about the following concept somewhere in boost but i can't actually remember...
@Alex: vectors "own" the objects inside them
@Alex: to do that, they make copies
@AlexReece It makes copies
@HardCoder1986 A move constructor is something new in C++0x, it's a constructor like MyObject(MyObject&&); which will move the object you pass as parameter
19:07
@Tomaka17, I haven't overridden the copy or move constructors, but there any variables instantiated with new in my class. Not sure if I need to override in this case.
@gMaN: I rarely use boost::tuples; don't know
@AlexReece: vector<T> v; v.push_back(T()); you mean?
like, returning a string declared as a local variable always made me uncomfortable
@RogerPate: I see what you did there.
@Bocochoco You'll have to override the constructors in this case or terrible things may happen
19:08
Ah, thanks
@GMan thats it
@Bocochoco But again if you use a smart pointer (unique_ptr or shared_ptr) instead of calling new then the problem solves itself
you use a smart pointer with calling new
@tomaka17, I don't know why I used a vector of pointers anyhow, I rewrite the code a bit, so it's now vector<T> instead of vector<T*>.
Yeah... I meant "instead of manually using new/delete"
If you don't override your class' copy or move constructor, then an implicit one will we created, and this implicit one will copy/move all your member variables
How STL containers delete user type. I think it should be something like t::~T() for variable t of type T.
19:11
If you use pointers in your class, then this is generally not what you want
Isn't that the idea of a copy/move constructor?
@Bocochoco No because you may want to copy the pointed object and not the pointer
The only pointers I have in this code are from SDL, which unfortunately uses them everywhere. I've been trying hard to use as few of them as I can in my own code.
So if you want to copy an object which stores a pointer to an SDL surface, you may want to copy the surface, not the pointer
Of course this depends on the goal of the variable
@dimba They call allocator::destroy(x), on an instance of an allcoator and an element instance x. By default, that's equivalent to x.~T();, where T is the type of x.
@Bocochoco Keep in mind a valid way of handling copies is to disallow them.
19:15
Basically the class I've got in my vector contains the x,y coords and a few other properties of an object, and the offset of the texture to use for it when it's drawn to the screen.
So, the only SDL_Surfaces that I have are *screen, and *textures
In your case you can forbid copy and allow a move constructor which will clear the pointer from the moving source
Damn, no one on the whole stackoverflow can help me with that trivial shit :(
@Gman thanks!!
@Tomaka17, how would I forbid the copy/move constructos?
@Bocochoco By declaring it private : class Object { private: Object(const Object&); Object(Object&&); };
19:17
@Bocochoco If your compiler supports it, do T(const T&) = delete; to "delete" the copy constructor. Otherwise just do it the old fashioned way of making it private and never defining it.
Is there a way to store a shared_ptr<T> as void *. I use 3rd party library (ACE) which store user data as void * and later on returns it back to the user.
Can anyone tell me ... Whether we can create instances of Abstract data types?
@Bocochoco why not make it virtual to override later so you do have a default constructor?
@dimba: you'll have to allocate a copy and use that as a void*: void *p = new shared_ptr<T>(other_shared_ptr_obj); // static_cast it back
@Pavitar: only as subobjects/bases of another type
@Bocochoco Why are you storing pointers to SDL_Surface in a class which stores coordinates and basic informations?
19:20
Whats this virtual now?
@Tomaka17, I'm not. The only references to an SDL_Surface in my class are offsets to use in an sdl_rect so the correct part of the textures surface is copied.
virtual will give you a base, but can be overridden later depending on what you want to adapt
@Bocochoco I think I'm confused with your problem :o
So am i :/
Heres my class:
typedef class object
{
private:
short id;
std::string name;
SDL_Rect offset;
public:
object(short i = 0, const std::string& n = "");
const std::string& get_name() const;
void set_name(const std::string &n);
const int& get_id() const;
} object;
If copying an instance of your class semantically means copying all the members, then you don't need to specify a copy constructor, you can use the implicit one
yay formatting failure :/
typedef class object
{
   private:
      short id;
      std::string name;
      SDL_Rect offset;
   public:
      object(short i = 0, const std::string& n = "");
      const std::string& get_name() const;
      void set_name(const std::string &n);
      const int& get_id() const;
} object;
19:22
EW, delete that typedef. You don't need it.
Saw that coming
Ok that class is good, there is no problem with copy/move constructor or anything
I didn't think so.
(you said earlier that you were using new in your constructor or something)
(I think I misunderstood)
I was using new with the vector<T*>
Still don't know why I used it that way
19:24
Ahhhhh... sorry
without typedef, I get errors when trying to create an instance of object. object(0, "A"); brings up an error expecting type
Did you remove the "object" at the end ?
Grah, I knew I forgot something dumb.
I need to stop using python. It's teaching me some bad habits
they have typedef in python?
By the way if you're interested in smart pointers, you can also use them instead of SDL_Surface*
19:27
No. I just try and fix things the wrong way now
@Tomaka17 you have my attention
@Roger Pate - I understand (yesterday saw "Being there") :)
For example your can write shared_ptr<SDL_Surface> mySurface(SDL_CreateSurface(...blablabla...), &SDL_FreeSurface);
mySurface is now a smart pointer to a SDL_Surface and will automatically call SDL_FreeSurface when necessary
Got an example of that? I've never seen smart pointers before.
@Bocochoco Which compiler are you using?
19:29
Version? Mostly, are you using C++0x support?
@Roger Pate - Is there a way without allocating a shared_ptr in heap? I don't want manually manage memory.
g++ v 4.5.0
I don't have c++0x enabled in the eclipse settings.
@dimba: not reliably if your only choice is a void*
@dimba Well, you need to be able to pass an address. If you can store it somewhere where it won't go out of scope, that'll work.
@dimba: in certain circumstances, you may be able to fudge things through a void*
19:31
@Bocochoco Okay. You just talked of move constructors, which is a C++0x thing. Well, if you did you could use std::shared_ptr.
oh yeah, if you can guarantee some local object will live long enough, just pass its address
@Gman, so the smart pointers are a c++0x thing as well, I take it.
@Bocochoco Smart pointers is a generic concept (ie. a pointer that automatically cleans the pointed object), but C++0x brings them in the standard library
Before C++0x you had to code your own smart pointer class, or use a smart pointer from a library (like boost)
No, smart pointers are irrespective of C++ version. (Except unique_ptr, which hinges on move semantics.) C++0x just made some standard, like @Tomaka17 says. Otherwise, you'd want to look into Boost or something.
I see.
19:35
@Roger Pate @GMan - thanks guys
There are two major smart pointers that we use: unique_ptr and shared_ptr
I don't think I need to do anything like that, given that I've only got two surfaces.
That's your choice ; if you become used to using smart pointers you'll start using them everywhere
@Bocochoco You will eventually, though, so you might as well make it correct now.
I agree.
It sounds like theyre just a user created class of a pointer.
19:38
They are.
Like I said way above, though, good C++ separates usage of a resource from the management of it. It should manage itself. That's all a smart pointer does: you use it, and the smart pointer takes care of the rest.
This is going to take a while for me to wrap my head around
It'll catch on. You'll find the keyword delete ugly.
user402642
Is there overhead when sending output to /dev/null?
I already find delete ugly, its caused segfaults enough already.
Personally I also start to find the new keyword ugly since I often use the make_shared function :)
19:42
@Carlo: Probably minimal. Why?
I think boost scoped_ptr is also useful as a smart pointer
it's like a better auto_ptr
It'
user402642
@GMan I have a program that, by default, sends output to '/dev/null' ... I can toggle between changing the output to /dev/null or to a file.
user402642
@Gman: so... most of the time, the usual STDOUT will be sent to /dev/null ... and when I send a signal to the program, it sends the output to a file
And I return with a question about ye old polymorphism...
19:46
@Carlo: I see.
say I have an array of type A, which has a function A::work() and A::morework() if I want to do function cahining in a loop such as anArray[i]->work()->morework() then A::work() would return an A* but what if I have B: public A that overloads A::work() should B::work() return an A* or a B*?
Thank you everyone. I'll see if I can't figure out how to use smart pointers.
so my array in question has elements some of which of type A and some of type B
You should return B*. This is called a covariant return type, since B* can be converted to an A*.
I want to say thanks <insert name> but can't quit bring my self to accept how win your name is... not that is
19:50
wat
lol... thanks... cool name :P
ty
That chat feature totally killed my productivity
20:06
I'm considering use smart pointers in middle size project, where raw pointers were used all around. From your experience how much it can hurt the performance? I know I need to do profiling. But before changing thousands of SLOC, I want to know if it worth it.
None at all, if you chose the right pointers.
All it does is guarantee it's going to be freed, how can that hurt? Over-using shared_ptr is probably the only risk, since it's a bit heavier.
@dimba It depends from the type of smart pointer; for simple ones (e.g. scoped_ptr/unique_ptr) there shouldn't be any overhead. For reference counted ones, there may be some slight overhead, but it should be the same you already have if you implemented such feature by yourself.
@dimba If you avoid passing values of smart_ptrs around you should be fine. But as other say, it really depends on your app.
ok, so is scoped_ptr is accepted in C++0x? Is std::unique_ptr and boost::interprocess::unique_ptr are similar?
No, there is no scoped_ptr in C++0x.
unique_ptr can be used in place of scoped_ptr.
20:11
IIRC scoped_ptr isn't included in C++0x because its features are almost the same of unique_ptr, which exploits the new move semantics allowed by C++0x.
@Matteo - this was my next question
Yea. scoped_ptr is a unique_ptr you don't move.
2
@Marcus - what do you mean by "passing values of smart_ptrs around"? When it becomes "around"? :)
I think I still don't have C++0x support in my gcc (it's pretty old version), so can I use boost::interprocess::unique_ptr and latter move to std::unique_ptr?
@dimba If you create a lot of copies of a ptr in order to pass it to funcitons etc etc then you're in danger of performance hits. If you just "store" smart-ptrs and only pass raw ptrs (or ref-to-smart-ptr) it should be better. (That's why i mostly use intrusive_ptr or shared_from_this.)
@MarcusLindblom: what do you mean for "copies of a ptr"? Are you talking about using intensively reference-counted smart ptrs?
20:17
@MAtt
Yeah.. precisely..
@MarcusLindblom
I don't know, I wouldn't mind so much about that... after all, a new copy of a `shared_ptr` should result in just an increment of the reference counter and other lightweight stuff... yes, it's not free as a `scoped_ptr/unique_ptr`, but it's not heavy at all.
@Matt
grmbl!!
@MatteoItalia It depends on what you're doing. I've had some apps spend 10-15% in the inc/dec of shared_ptrs due to careless copying.
@MarcusLindblom: whoa, I didn't think it could impact so much. :S
@MatteoItalia That's why you need to profile. ;)
As usual :)
20:23
@MatteoItalia It all comes down to inner loops, thread contention, etc and so on... as always.
but yeah.. ;)
love the SO/SE chat btw.. really neat and well implemented!
What's a good free IDE for C++ on Windows?
user402642
Visual C++
@MarcusLindblom: Yes, it's nice to see how well can be implemented such stuff.
Visual Studio Express? Qt Creator? ... of the top of my head..
Visual Studio Express, CodeBlocks, meep.
20:25
other than VC++ :S
@GioBorje: why "other than VC++"? With the Express edition you can do much stuff without problems.
Not that the other ones aren't worth using, eh, they too are fine.
There's also Eclipse with C/C++, but I've never used it for anything but toy testing projects (aka HelloWorld) ;)
I've used Eclipse for Java/Python though. Works well enough..
I heard about CodeLite, did anyone use it? How does it compare with e.g. CodeBlocks?
I use VC++ but some friends of mine want alternatives because they can't get it to work or some other personal preferences
did someone make visual studio work with gcc?
20:30
Is it worth doing it? In my experience, on Windows usually VC++ does better than MinGW in terms of optimization.
But I'm talking about tests done some years ago, I don't know if the situation changed.
probably you're right, just sometimes when you want to be able to test your code using both gcc and cl
it might come useful
Yes, you're right.
However, I think that the VC++ IDE is bound to its own compiler.
On the other hand, you may use Code::Blocks both with the VC++ compiler and MinGW, Intel compiler, etc.
Well, actually I do think this can be achieved using some 'custom build events', etc and just maybe someone did it?)
Maybe you can do it by creating a project that uses makefiles to build, IIRC it was possible.
Hm, probably yes.
20:33
@HardCoder1986 Yeah, you could just make a "utility project" that just runs 'make'... pretty easy.
Or 'makefile project' rather..
Also on the side, does anyone know if I should use primer when spray painting a keyboard?
point is, it can be done. :)
I do know that at my previous company they did it when they had a project (game) and used vs to develop the game core and the integrated gcc to make this stuff run in PS3 environment
I just didn't have a chance to examine how it was implemented)
I think that the makefile project is the way to go.
@GioBorje It might help. Be sure to roughen the surface a bit first though, apply several layers and use some coating surface on top afterwards. Plenty of DIY paint help available on the net..
coating surface = "clear" paint .. whatever you call it in English.. ;(
;)
(where's my undo/edit button!?!?)
20:35
Hm, yes. I'll give it a shot if i have free time, thanks everyone.
lol. I'm going for a homemade das keyboard and it's difficult to type atm without keys
Well, I too was thinking about clearing the letters from my keyboard. I had the proof the other day that I don't need them at all. :)
why do you need VS to run make? just... run make
@MatteoItalia Not necessarily. The Intel C++ Compiler for Windows has very tight Visual Studio integration, for example.
20:41
@JamesMcNellis: I never worked with it, nice to know. :)
20:55
If you don't initialize a bool member of a class, does it have any guarantees to its contents?
So if I read it's value is the behaviour undefined?
its*
"the behaviour undefined" sounds so fancy.
20:58
What about globals? Scalar types should be guaranteed to be initialized to zero, what does it happen with objects?
See; I don't like this chat already. If you had asked that on Stack Overflow, I'd have gotten at least ten rep per letter of that first answer ;-) [I kid]
3
@Matteo: They are zero-initialized before any other initialization takes place, if any.
Which, for bool, means a value of false.
@GMan: thank you.
Mhm.
21:07
Is stackoverflow.com really slow for anyone else today?
I must be reloading the page too frequently.
and how much time do you guys spend here?
Either that or it's the extra latency to the new datacenter :'(
Hi Rob!
21:09
@JamesMcNellis Doesn't seem different to me.
You should definitely stop reloading so much. Maybe once an hour would be good.
Once an hour!
Yes!
:]
what's the general view on function names for classes, should the imply what the caller wants the to do to the class or what the class will do ie, should enemy.DealDamage() reduce the health of enemy or should it work out how much damage enemy can do
21:19
Does anyone have any experience with libcurl?
(Or does anyone know of an alternative, as I'm having problems getting libcurl to work)
@thecoshman I would imagine the function reduces the health of the enemy.
exactly, function should say what it does
so generally, a function should imply what it will do to the object you are calling iton
The function name should tell you what the functions going to do, yes.
Can any body tell me how to marshall stl containers(maps,list,vectors) and all STL based generics to .NET Generics in c++/CLI
like std::list should be converted(marshalled) to List<T^>^
and map should be converted or marshalled to dictionaries
21:23
@Usman: I think that such question would be better suited on SO; IMHO the chat shouldn't be used to ask "big" questions.
@MatteoItalia "SO"...?
could'nt get..
@Usman: StackOverflow, the main site.
@Usman: i dont think, theres an easy O(1) solution...
u mean posting the questions on forums and making it tag
coz I posted the problem but after passing half an hour or more still did'nt got any comment or answer on that
@Usman Yes. If everybody used the chat this way, it would become a mess and defeat both its purpose (as a "third place") and the purpose of the main site.
21:26
I was just thinking that, this chat feature whilst good for comunity is libale to destroy what SO is really for
@Usman Heck, it's half an hour, not a week! It's not a paid 24/7 support line, it's just a site where people who have time answer to questions!
@Matteo Italia : no problem and no offense i just expressed and nothing...
BTW can u please tell me wot then actual purpose and meaning of this "third place"
I mean people should have chat of what kind other than this...?
The chat should be for discussing small issues, not large ones, or anything "meta-C++".
Isn't there somewhere some kind of guidelines for what should go on chat an what shouldn't? IMO a written wiki would help newbies quite a bit.
Does it really matter? If someone can answer it here, why not, even if it's a bigger thing?
21:30
I'd like to know people's thoughts on using forward declarations vs. including headers. That is, when you have the option (so, not when you have to use a forward declaration), do you include a header or use a forward declaration?
Depends on the case
Headers if there are multiple functions I need
@Dragory: IMO it defeats the whole idea of SO. We struggle to keep it a tidy place, we whine about the accept rate, the tags, the upvotes/downvotes and everything and then it's ok to throw in any big question in chat? :S
Well, you have a point...
@JamesMcNellis include the header, if/once build times become a concern, then look at refactoring
@MatteoItalia: well, that's chat ;)
@Dragory I've used libcurl a few times and it's worked fine.
21:33
Its always better to use Forward Declaration unless you need to include Header file
@RogerPate Well, that's my opinion, and having worked on several large projects, I've never encountered "concerning build times." But apparently there are a lot of people that are in favor of using forward declarations everywhere, and I don't understand why.
I think that forward decelerations are messy. I would try to leave them out if possible. And just so I am sure we are talking prototypes aint we, such myfunc(float var);
if your file is b.h and you are using something in a.h, if forward declaration of a is sufficient, then do Class A
@RichardHarrison My program seems to crash as soon as it gets to the curl_easy_init() function ( stackoverflow.com/questions/4008921 )
@JamesMcNellis: half of those people are prematurely optimizing, the other half are prematurely optimizing and know it
21:34
advantage is if c.h is using b.h, it will not get a.h
@James: If the project allows for it (it makes sense), I often create a project_fwd.hpp file that can be used sometimes. But generally I just include.
@GMan: That doesn't sound unreasonable; at least then all the forward declarations are in one place and you can easily comment where things came from.
@Koteswarasarma: woe betide you when you use something that relies on koenig lookup (e.g. swap) and you end up breaking the ODR
when you have to refactor to use forward declarations, use a "blahfwd" header
wow, for once I am actually using enum rather then making up some lame ass work around to get the same functionality with out actually using an enum. Not sure why, but I always fail to think of it as a c++ feature
YAGN forward declarations 99% of the time
21:37
@RogerPate I did not get you
@Koteswarasarma: templates that use ADL (argument-dependent lookup, aka koenig lookup) break the ODR if they are called in a scope where that candidate isn't available and in one where it is
template<class T> void blah(T& a, T& b) { /*do stuff*/; swap(a, b); /*moar stuff*/; }
since practically all value types will have a swap, it's a handy example, but applies to operator overloads and other cases
speaking of which... any real downside to using enums?
Not really
if injecting the names in the outer scope doesn't bother you, nope
Is there gcc compilation option(s) to catch 64 bit platform errors?
21:41
I often wrap enums into a namespace to avoid that.
well... if we go on the theory of what you don't know can't hurt you.... then I have no worrys :P
@GMan: but then you can't use BLAHT var = BLAHT.enumerator; :)
T var = TNS.en just irks me for some reason, but I do it too
Yeah
Okay, how do these chat flags work? I see it, what are we suppose to do?
I see what you did there.
21:47
Agreed
You're talking about the flag / star / link buttons on the right side of the messages?
@JohnatCashCommons: 10k users see offensive/spam flags
(for all rooms)
and on every page at chat.*
It's kind of obnoxious.
See them? Where?
Maybe I don't see them, then. :O
21:53
So it's the blue circled "1"? I'm not seeing that. That means I haven't been flagged yet?
that means you don't have 10k rep on SO
Mine is a square, not a circle.
Ahhhh ... I saw "10k users" and translated it as "10,000 users" not "users with 10k rep." Gotcha. :)
@JamesMcNellis: upgrade your browser to chrome :P
@JamesMcNellis Weird. Mines a circle.
21:55
Yeah, yeah, yeah... I use Chrome; just not at work.
Tsk tsk. I bet he's using IE, let's chuckle at him.
chuckle
ty
not a sheep

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