Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Initializing (const char name[], const char phone[])

Status
Not open for further replies.
Feb 16, 2003
2
0
0
US
I am trying to inizialize:
Person::person(const char name[], const char phone[])
{}

class Person
{
enum { NAMELEN = 81, PHONELEN = 7 };
protected:
char name[NAMELEN]; // null-terminated string
char phone[PHONELEN]; // *not* null-terminated
};

the thing is that the protected data that i am using is name and phone. It keeps telling me that points and const cant work. i have tried using strncpy, strcpy, neither are working if anyone can help that would be great.
 
you could try declaring the enum outside of the class:

enum data { namelen = 81, phonelen = 7 };

then in your protected:

data dt;

do some pointer stuff instead of array stuff in protected:
char * m_name;
char * m_phone;

then I think is your real problem is using const, you can't modify a const variable, so to initialize it in your constructor, you have to use the initializer list

Person::person(const char * name, const char * phone) : m_name(name), m_phone(phone)
{ } The weevil of doooooooooom
-The eagle may soar, but the weasel never gets sucked up by a jet engine (Anonymous)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top