I have created a C++/CLI (Visual C++) project in visual studio 2010 professional. I then added a very small C++ class to the project. Followng is the code
#include <stdafx.h>
#include <iostream>
using namespace std;
class Tester
{
public:
Tester(){};
void show()
{
cout << "OKOK..Printing" << endl;
}
};
Now, I dragged and dropped a button to the automatically built GUI form, and I am about to call the above code from the button. Following is the code of the button.
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Tester ^t = gcnew Tester();
//Test t; - giving errors as well
}
};
When I execute the code, I get the following error
1>------ Build started: Project: testdamn, Configuration: Debug Win32 ------
1>Build started 7/1/2013 12:59:38 PM.
1>InitializeBuildStatus:
1> Touching "Debug\testdamn.unsuccessfulbuild".
1>GenerateTargetFrameworkMonikerAttribute:
1>Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
1>ClCompile:
1> All outputs are up-to-date.
1> Test.cpp
1> testdamn.cpp
1>c:\users\yohan\documents\visual studio 2010\projects\testdamn\testdamn\Form1.h(79): error C2065: 'Tester' : undeclared identifier
1>c:\users\yohan\documents\visual studio 2010\projects\testdamn\testdamn\Form1.h(79): error C2065: 't' : undeclared identifier
1>c:\users\yohan\documents\visual studio 2010\projects\testdamn\testdamn\Form1.h(79): error C2061: syntax error : identifier 'Tester'
1> Generating Code...
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.86
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I also noticed when I removed the class call from the button, the program build fine. So, how can I call to these C++ classes from C++/CLI ?
#includethe Tester class's header file into the GUI form?'Tester' : undeclared identifier. Also, you can't treat it like a .Net class.^tandgcnewwon't work.