Hey,
I have been trying to pass a class variable to another class but I have no clue how to do this...
Here is the basic code I have been fighting with :But apparently I got the following errorsCode:#include <iostream> using namespace std; class Text { public : char words[80] ="This is a text line"; }; class Line { public : void showtext(void) { cout << words; } }; int main() { Line line; line.showtext(); cin.get(); return 0; }I understand the last error(but I have no clue how to pass char 'text' to class 'Line')ISO C++ forbids initialization of member 'text'
error : making 'text' static
invalid in-class initialization of static data member of non-integral type 'char[50]'
In member function 'void Line::showtext()':
'words' was not declared in this scope
But I don't understand the first 3 errors, I mean why would it forbid initialization of 'text'.
I hope you guys can help me figure out what my problem is and how to pass a variable from one class to another.
Thanks in advanced.