Quote:Original post by Gage64Cheers for replying this far. :)Quote:Original post by Mybowlcut
XImage's default constructor is just empty. It calls Surface's default constructor because it's the default constructor - I don't get why this is an issue.
It's not necessarily an issue. It's just that when you have a constructor that does nothing, you are enabling the creation of the object with an undefined state (i.e., the object's member variables contain garbage values).
Often people just stick an empty default constructor for their classes out of convenience. I just wanted you to think if you really need it.
Anyway, you say that after you call read_data(), the vector of images contains garbage values. Did you step through that function with the debugger? (this is actually the first thing I should have asked)
EDIT:Quote:read_data just returns a container of objects as specified from the file... The problem is there. Once the image is constructed and read_data finishes, I look at the contents of v and it has the image but the internals of the surface are all messed up
Actually it sounds like you did this already.
One other thing - does XImage has a proper copy constructor?
I remember reading somewhere that using the operator= function as a lazy replacement for a copy constructor is bad practice... is that right?
XImage::XImage(const XImage& rhs){ *this = rhs;}XImage& XImage::operator=(const XImage& rhs){ if(this == &rhs) return *this; this->name = rhs.name; this->file_name = rhs.file_name; this->surface = rhs.surface; this->position = rhs.position; this->is_colour_key = rhs.is_colour_key; this->colour_key = rhs.colour_key; return *this;}
template <typename Object, typename Container> Container read_data(std::istream& file) { Container v; //if(get_file_size(file) == 0) //{ // Empty; return early. // return v; //} std::copy( std::istream_iterator<Object>(file), std::istream_iterator<Object>(), std::back_inserter(v)); return v; // here }
Ah... I tried some more testing:
Surface s1("3.png"); { Surface s2("3.png"); } return 0;
[Edited by - Mybowlcut on September 2, 2008 5:50:55 AM]