Overhead

G

Garma

When define member like "string" type for a class, we can either define it
as "char *" or "string." I don't know which one should be better. My
concern is that "string" has some "overhead" though its usage is so
convenient. Additionally 'string' member could be needed to pass into a
function which expect a variable of 'char *' Then the function call could
make the code looks like,

function(TheObject.PassMeTheStringMember().c_str(), 12, ...);

This is not that readable to me. I want to hear your opinion about this.


Another question is related to using STL. There are two classes, A and B:

class A
{
private:
list<Class B>InnerList;
....
};

class A contains a STL list. Could objects of type class A be put in
another std::list, OuterList (you see an iteration here)? Could it be put
in other type of container?

Thanks for your comments!
 
D

Donovan Rebbechi

When define member like "string" type for a class, we can either define it
as "char *" or "string." I don't know which one should be better. My

You need to manage the memory somehow. It is usually better to avoid managing
multiple dynamic memory allocations within the one class (causes all sorts
of problems with exception safety, and makes code less clean). So you would
probably need to use *some* sort of class to manage the storage anyway.
concern is that "string" has some "overhead" though its usage is so
convenient.

What type of overhead ? Is this "overhead" causing any problems in your code ?
Additionally 'string' member could be needed to pass into a
function which expect a variable of 'char *' Then the function call could
make the code looks like,

function(TheObject.PassMeTheStringMember().c_str(), 12, ...);

This is not that readable to me. I want to hear your opinion about this.

In my opinion, it's readable (but it would be more so if you used shorter names
for your member functions!)
Another question is related to using STL. There are two classes, A and B:

class A
{
private:
list<Class B>InnerList;
...
};

class A contains a STL list. Could objects of type class A be put in
another std::list, OuterList (you see an iteration here)?
Yes

Could it be put in other type of container?

Yes

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top