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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Initializing cString in Contructor 3

Status
Not open for further replies.

kassandra123

Programmer
Jan 28, 2004
1
US
I am new to C++ and I need to know how I can initialize a cString in a constructor. For example, I need to initialize name to unknown. I know this is probably really simple but I cannot find an example or I am looking in the wrong place. Thank you for the help.
 
Try

MyClass::MyClass()
{
myString = "Unknown";
}

You can also initialise it using another method, but I am not too sure of the syntax for initialising it outside the braces.
 
Also you may do it likt this:

MyClass::MyClass: myString ("Unknown")()
{
}

Ion Filipski
1c.bmp
 
MyClass::MyClass():myString("Unknown"){}

/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
Is great that, but you may have a problem. How do you handle the situation than someones name will be "Unknown" but someone else's nake will not be known...?

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top