• Advertisement
Sign in to follow this  

Class in a list, addin values

This topic is 3593 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have this class Project: class Project { public: char name[40]; int duration; }; I wanted to put it in a list and add some values,. But it aint working. Any help appreciated. list <Project> proj; proj.push_front (Project("AA", 1));

Share this post


Link to post
Share on other sites
Advertisement

class Project {
public:
Project( char* n, int dur ) : duration(dur)
{
strcpy( name, n );
}
char name[40];
int duration;
};

Share this post


Link to post
Share on other sites
Quote:
Original post by Molle85

class Project {
public:
Project( char* n, int dur ) : duration(dur)
{
strcpy( name, n );
}
char name[40];
int duration;
};


Project(const char * n, int dur) : duration(dur)
{
strncpy(name, n, 39);
}


In the brief example above, we see why use of std::string is generally recommended.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement