Therefore I have(1) "VCApp.cpp" having "main" function. (2) "A.cpp" is new file name where I want to add my class A. And then I want to access that class in my main function.
Following is my defination of class "A" which I want to put in "A.cpp"
public class A{
public:
A()
{
Console::WriteLine("Inside A constructor.");
};
};
and I access the class A in my main function as following way ,
int main(array
{
A* o = new A();
return 0;
}
I put above code and while building, found following compile time error(s),
----------------------------------------------------------------------------------
fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
error C2065: 'A' : undeclared identifier
error C2065: 'o' : undeclared identifier
error C2061: syntax error : identifier 'A'
----------------------------------------------------------------------------------
To get around of this error (1) Add the following line in A.cpp at the top of it.
#include "stdafx.h"
(2) Add the following line to the top of "VCApp.cpp" file,
#include "A.cpp" ---- adding this line helps compiler to refer defination class A to find in "A.cpp" file.
Now if I compile the code then there is no compile time error and I got following out put in my console output,
Inside A constructor.
Press any key to continue . . .
Happy coding !!!
No comments:
Post a Comment