Yeah, as long as you have a constructor for the class that takes a char* type.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
class CChess
{
public:
CChess(char* pointer) {classText = pointer;}
private:
char* classText;
};
//then in main you could
int main()
{
char text[80];
cout << "enter text:";
cin.getline(s, 80);
CChess s(text); //classText inside the CChess class will have the value of text.
}
I hope that was what you were asking :P
EDIT:
But in this case it's not really called casting. It's just using the constructor of a class to fill out class data.
If you want to take one object and from it create a class you defined yourself, you have to define how it is done. Here is one way; a constructor is made that takes a char* and does something with it.
@hamsterman
Lol, wayy to many simultaneous replies.
Plural is correct, because there are multiple forums. Or multiple sections.. Maybe there is only one forum? So then it'd be "Is the forum overcrowded" ... The world will never know.
This is typecasting
I suppose that's right. It's weird thinking of it as typecasting because you made it. But i guess that's how other type casting works.
It's getting a bit ridiculous.. Maybe I should stop coming here so often.
Maybe there is only one forum?
That's what I want to know. In http://www.cplusplus.com/ there is a link "Forum" which implies that there is only one, but then on http://www.cplusplus.com/forum/ there is a table of forums which would imply that there are many..