Nov 2, 2012 at 5:46pm UTC
I created a header file called view.h
class View
{
public:
void showLoginScreen();
}
A cpp file called view.cpp
#include<iostream>
#include<string>
#include"view.h"
using namespace std;
void View::showLoginScreen()
{
string user;
char* pass;
cout<<"Enter Your Username:\t";
getline(cin,user);
pass=getpass("Enter Your Password:\t");
}
main.cpp file
#include<iostream>
#include"view.h"
using namespace std;
int main()
{
View obj;
obj.showLoginScreen();
return(0);
}
When I am compiling the main.cpp file I am getting an error message:
In function 'int main()'
View was not declared in this scope.
Expected ; before obj.
obj not declared in this scope.
What is the cause of this problem?
Nov 2, 2012 at 9:50pm UTC
You need a semi-colon after the class definition.
Nov 3, 2012 at 2:02am UTC
Semi colon didn't solve the problem.
Nov 4, 2012 at 6:30am UTC
The code is working fine when I am writing the entire code in a single file. But the compiler is throwing error when I am using 3 separate files.
Nov 4, 2012 at 3:14pm UTC
Well for me, writing it in three separate files as in my post above and compiling it with the command line as above works fine. If you do the exact same thing and it doesn't work, the problem is not with the code.