Problems with classes & objects

May 30, 2011 at 8:12pm
Hi, I am trying to learn to use classes and objects, but I'm having some problems. I'm not sure where I'm meant to define the class. Is it before int main ()?

Also, do I need to type #include <"name of class"> somewhere in the program?

Any help would be greatly appreciated.

Thanks - Enterprise D

May 30, 2011 at 8:35pm
Have you looked at http://www.cplusplus.com/doc/tutorial/classes/ ?

In C++ all declarations have to be written before they are used.
#include is needed is you have your code in several files and does not necessarily have anything to do with classes.
May 30, 2011 at 8:36pm
http://www.cplusplus.com/doc/tutorial/classes/

Also, do I need to type #include <"name of class"> somewhere in the program?


When you #include <"something"> the preprocessor goes looking for a file named something and copies that exactly into your code at the place where you put #include <"something"> . Whatever that file is gets copied in, right there. If you defined your class in some other file, then you could use the #include to copy it into your code. There is no requirement to do that.

Last edited on May 30, 2011 at 8:40pm
May 31, 2011 at 1:04pm
Thank you very much.

Enterprise D
Topic archived. No new replies allowed.