GUI calling a class

Hello I am new to C++ and used to java. I have created a GUI which I need to call and execute a class file. I have been helped by someone but unfortunately the code shows error and I dnt know whats happening since I am clueless in C++

Basically this is the code

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {


IOFile^ form2 = gcnew IOFile;

form2->Show();
}

Error 1 error C2065: 'IOFile' : undeclared identifier 88
Error 2 error C2065: 'form2' : undeclared identifier 88
Error 3 error C2061: syntax error : identifier 'IOFile' 88
Error 4 error C2065: 'form2' : undeclared identifier 90
Error 5 error C2227: left of '->Show' must point to class/struct/union/generic type 90


If anyone knows how to call the class please let me know

Thanks in advance

closed account (jizbqMoL)
Are you including the header file in which IOFile is declared, and/or is IOFile in a namespace?
@ embooglement,

yeah the IOFIle is included and the IOFile is in a namespace,

This is the IOFile.h code, just a trial code



#include <iostream>


using namespace std;

int main ()
{
cout << "Hello World!";
return 0;
}

Did you use "quotation marks" or <angle brackets> to include your header file?
Last edited on
I used quotation marks for the headers.
closed account (z05DSL3A)
There is a big gap in your understanding. I'm trying to think of a good way to point you in the right direction but...

Basically the first post has some C++/CLI code that looks like it is from a Windows forms application (.net) and it looks like the code is trying to show another form. The code in the header file is C++, although C++ and C++/CLI can be mixed it is not advisable while you are trying to find your way (and this is not the way to do it).

Do you wish to learn C++ or programming for the .net platform?
Basically the first post has some C++/CLI code that looks like it is from a Windows forms application (.net) and it looks like the code is trying to show another form



Thanks Grey Wolf for the reply, I would like to learn programming for the .net platform, I have gone through the tutorials in the Visual Studio express c++2010.

The code in the header file is C++, although C++ and C++/CLI can be mixed it is not advisable while you are trying to find your way (and this is not the way to do it).


You are right, I am trying to call a class file when I click the button, thats all. So what way is the best way, I have done this in java and its soo easy and fast, I am just getting frustrated with this.



Thanks for all replies
closed account (z05DSL3A)
I would like to learn programming for the .net platform...

<My opinion> C++/CLI is possibly the most complicated and least well documented of the .net languages. My recommendation, if your overriding goal is to program on the .net platform, is to start learning C#.

Although this will not answer your question directly it may be worth giving the following a quick read.
http://msdn.microsoft.com/en-us/magazine/cc163852.aspx

If you do want to learn C++/CLI, post back and we'll see what we can do to help.
yup I would like to learn c++, but its just that time is running out for me, is there any place that I could be referred where it deals with what I need directly.

Thanks
Hmm, is what you quoted really what is in your IOFile.h file?

In that case :
- There is no definition of IOfile in IOFile.h, so i find it logical that the compiler doesn't know what it is
- Why do you have a main() in a header file?
closed account (z05DSL3A)
I have not been able to find a good tutorial for C++/CLI.

I'm a bit busy at the moment bet the general gist of what you are trying to do is:
1
2
3
4
5
6
7
8
 //...
ref class ManagedReferenceType
{
int aPrivateField;
public:
void APublicFunction();
};
//... 
ManagedReferenceType.h

1
2
3
4
5
6
7
8
9
#include "ManagedReferenceType.h" 
//...
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) 
{

    ManagedReferenceType^ aRef = gcnew ManagedReferenceType();

    aRef->APublicFunction();
}
your form code

The main problem with your original code is that you did not define a class in the IOFile.h and you therefore you could not insatiate one in the click handler.

I would recommend getting hold of a good book on C++/CLI, something like
Pro Visual C++/CLI and the .Net 3.5 Platform
by Stephen R. G. Fraser

APRESS do a few books on the subject
Thanks alot, the book looks good, I had a look at it and will do. btw when I try and run your coe it shows the same error as the 1st post. Any suggestions why?

Thanks
closed account (z05DSL3A)
because it is not full implementation of of the header file/class but more of a flavor how you go about it (it was never intended to be compiled).
Topic archived. No new replies allowed.