it has a default constructor (that does nothing). when i create an object like this
newCustomer = new Customer;
what is the size of the name string? how does it allocate memory for this? i just need it to hold about 30 characters at the most and want to make sure it's not creating a huge memory space for it.
Implementation-defined. The implementation may implement "std::string" in anyway it wants, so long as it abides by the rules stated in the C++ standard. Use "sizeof()" to query the size of class, or piece of storage.
bradleyy1012 wrote:
"how does it allocate memory for this?"
The data members of "Customer::name" are pushed onto the program's stack. The memory allocated internally to "Customer::name" is allocated prior to "newCustomer"'s construction.
bradleyy1012 wrote:
"i just need it to hold about 30 characters at the most and want to make sure it's not creating a huge memory space for it."
Usually the memory for values entered in an object of type std::string is allocated dynamically and does not influence on the size of your class Customer.