Hello, again :P
I´ve got a problem with my class, im writing the class in a .h file and having inte main() on the .cpp (im very new to this so i´m writing down everything i have done)
I want the program just to ask a simple question about what the name of the game shall be, i have done it before, when the class and int main() both were on the .cpp file.
When I try to do the same, I get the error message : Error c2512: 'game': no appropriate default constructor available.
Here is the code.
and here is the .h fileCode:#include <stdio.h> #include <iostream> #include <stdlib.h> #include <conio.h> #include <string> #include "ClassGame.h" using namespace std; int main() { string nameOfGame; game myGame; //Guessing that it is here the problem is starting. cout << "Please enter the name of the game\n: " << myGame.getGameName(); getline(cin,nameOfGame); myGame.setGameName(nameOfGame); myGame.displayMessage(); getch(); return 0; }
Code:#include <stdio.h> #include <windows.h> #include <iostream> #include <string> using namespace std; class game { public: game(string name) { setGameName(name); } void setGameName(string name) { gameName = name; } string getGameName() { return gameName; } void displayMessage() { cout << "This is a game called: " << getGameName(); } private: string gameName; };



LinkBack URL
About LinkBacks



.
