April 28, 2024, 11:57:28 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


OOP baby steps

Started by kryton9, July 24, 2006, 01:49:33 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Ionic Wind Support Team

Not even sure that's a valid file name ;)


#include "k9 - 11 oop baby steps.inc"
// additional classes

//MyWindow Implementation
MyWindow::MyWindow()
{
}

MyWindow::_MyWindow()
{
}

MyWindow::OnClose(),int
{
Destroy();
return 0;
}


Was the only change I suggested.

If your building a project the .inc does not belong as a file to compile in the "file view".

So in your case the file view would only have:

main.src
classes.src
functions.src

It is a common newbie mistake to add an include file to the build.
Ionic Wind Support Team

kryton9

July 31, 2006, 10:05:35 PM #26 Last Edit: July 31, 2006, 10:13:47 PM by kryton9
Paul, I tried that.

It must be a valid name as in my earlier examples it worked.

I also wrote about not putting the includes into the project so I knew about that.

don't know what is wrong?

I attached the files.

Ionic Wind Support Team

Actually the last problem, which I didn't spot until now ise this:


// additional function implementations

global sub Help(int *pwin2)
{
pwin2->WriteText(30,35,"Pointer to Class Test"); // this is where I get the error unknown class
}


Should be:


// additional function implementations

global sub Help(CWindow *pwin2)
{
pwin2->WriteText(30,35,"Pointer to Class Test"); // this is where I get the error unknown class
}


you can't derference an INT and expect the compiler to guess it's a class.  Also the declare extern would be:

declare extern Help(CWindow *pwin2);

Just too hot in here to think straight ;)
Ionic Wind Support Team

kryton9

Ok, that did it :)

What is funny before I posted today for help. I have been working on that since yesterday(Sunday).
I tried every combination possible.
I had tried MyWindow and never thought about CWindow.

So is it safe to assume then that you have to go back to the first base class that your class came from in assigning the pointer?

Ionic Wind Support Team

The compiler has to know the class before a pointer can be dereferenced.  You could have changed the declare extern as:

declare extern Help(MyWindow *pwin2);

But that would require including that file in functions.src so the compiler knows what the class is.  I gave you the easiest solution since you were referencing a method in the base class (WriteText).
Ionic Wind Support Team

kryton9

Thanks to Paul, we finally got a working example that sort of covers the basics as I see it of OOP and also using Aurora with mutiple files in a source file.

So here is the final code, to help clear up any confusion from my conversation back and forth with Paul.

I guess the main thing to learn from all of this is that the pointer has to by typed to the class that the method is coming from. In my case, MyWindow came from the Base Class CWindow and the method WriteTextÂÃ,  is a method of CWindow and hence my big mistake.

What I learned so far from all of this and I hope this helps with the ideas:
Basically it comes down to 5 Steps. These can be in one huge source file, or as we have seen broken up.
1. You need to declare/define your variables, classes, functions
2. You then show the implementation of the above for classes and functions, that is write the code for it.
3. You then Create/Instantiate your objects from your classes.
4. You use them
5. Clean up before exiting your program.

If you break it up and don't put it all in one source file:
Step 1 would be your include file.
Step 2 would be in your source files
Step 3, 4, 5 in your main source file.


Ok, I will just attach the working code files to save you from having to make the project again. Don't forget to open the include file too to look at the code.

I will work on something small, but like this with a little more meat to keep on learning.

Working Code for Step 11 Attached: