Assuming that we have already have a working "Hello World" project it is rather simple to add a class. Just open the "HelloWorld" project (if it is not already open" and go to
Project > Add Class
Next choose a name for your class, say a "Point", and type it in as the name. You can choose to put the .cpp file and the .h file in different directories if you wish (click button next to filename). Check the virtual destructor box if you wish to inherit from this class at some point. Click on finish.
Now select the header file (
Point.h) and add two
doubles, "x" and "y" as public data types.
Next go to the main file (
HelloWorld.cpp) and include the new class so this file can use it. We do this by writing the following
at the top of the file.
We can now use the
Point class with the main file. Inside your
main function, declare a
Point "a". Assign the "x" and "y" members of "a" to some value, and write a command to print them out to the screen.
Now build the solution and hopefully you should see something like:
Including NAG dll
Optimising your programs