|
-
August 8th, 2006, 10:21 AM
#1
Classes
As a novice programmer, I've never used classes before. I've just created a project that has two main functions; of course this wouldn't work without a class structure. I'm having trouble figuring out where to get started and how to go about organizing classes and creating a header. Any help would be much appreciated.
-Thanks
-
August 8th, 2006, 11:00 AM
#2
Re: Classes
There're two simple ways you can follow to create a header and implement the class/es that resides within it.
First: if you're using Visual Studio you can use the wizard just fill the fields with the required information and the wizard will create the header, the class, and the cpp. (It will also implement the default constructor and destructor).
Second: Create files separately and then add them to the project in which you're working on.
I suggest you to read some information available on the internet before using classes. It's important that you understand what they are and how they work.
There're several sites dedicated entirely to C++ with plenty information, you can start reading there and if you encounter problems just let us know and we'll try to help you.
MSDN (MS Developer Network)
CPlusPlus (C++)
CProgramming (C/C++)
Hope it was helpful.
Last edited by CPPFanatic; August 8th, 2006 at 11:07 AM.
People who think they know everything really annoy those of us who know we don't. - Bjarne Stroustrup
-
August 9th, 2006, 01:10 AM
#3
Re: Classes
This is the right place to start - What are good books about C++ ?
And you cannot have two main functions - there would be one main and one ordinary.. - sorry but I had to pick.
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
-
August 9th, 2006, 02:27 PM
#4
Re: Classes
Thanks guys, appreciate the help...
So I've already created two .cpps and added them to an existing project. Can I get visual studio to automatically create the header?
Last edited by dantheman88; August 9th, 2006 at 02:31 PM.
-
August 9th, 2006, 06:03 PM
#5
Re: Classes
No you can't. Just click File --> New --> File and select the header option (.h). and create the header manually.
-
August 10th, 2006, 01:15 AM
#6
Re: Classes
So I've already created two .cpps and added them to an existing project. Can I get visual studio to automatically create the header?
1.
When you create a cpp file from the file menu, all you do is create an empty cpp file, that is it, nothing else.
If u want this to be included into the project, first save it and then from the solution explorer - Add this existing file into the project. Now this file is part of your project. Nothing else is generated.
2.Another way do do (1)
From the solution explorer, Add a new item. (say a cpp file). Now this cpp file is created, saved and also added into your project.
When u create a class from the class wizard, usually, it is here that a .h file for that class and a .cpp file is created simultaneously and added into your project. And of course, they are not empty files like earlier, the wizard has written some obvious code for you.
C++ program ran... C++ program crashed... C++ programmer quit !!   
Regards
Shaq
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|