Quote:
Originally Posted by MTK358
Maybe, but isn't it possible to somehow tell the compiler that I don't want to initialize anything?
|
How will the compiler know if or when to call the destructor then?
Quote:
Originally Posted by MTK358
I still don't understand what's wrong with creating an empty space of sizeof(std::string) and then assigning a value to it like this:
Code:
var = std::string("example");
where "var" contains an uninitialized value the size of an std::string.
|
Have a union with
std::string* and
int then, and
delete the
std::string* when necessary. And if you're that worried about space, just use a
char* and manage the allocation yourself.
Quote:
Originally Posted by MTK358
I thought that complex data structures are just a series of bytes no different from an integer, and that copying them involves just copying every byte.
|
One of the most basic principles that everyone should know about C++ is that this isn't at all true.
Kevin Barry
PS About that last comment, it's something that should be included in all C++ tutorials. The tutorial I learned from left out a lot of important things that I learned the hard way, even after learning much more advanced concepts. The lesson is that not everyone who thinks he/she is knowledgeable enough to write a C++ tutorial actually is.