CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Classes

  1. #1
    Join Date
    Jul 2006
    Posts
    35

    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

  2. #2
    Join Date
    Apr 2006
    Location
    Buenos Aires - Argentina
    Posts
    31

    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

  3. #3
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

  4. #4
    Join Date
    Jul 2006
    Posts
    35

    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.

  5. #5
    Join Date
    Aug 2006
    Posts
    157

    Re: Classes

    No you can't. Just click File --> New --> File and select the header option (.h). and create the header manually.

  6. #6
    Join Date
    Sep 2004
    Location
    A Planet Called Earth... :-)
    Posts
    835

    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
  •  





Click Here to Expand Forum to Full Width

Featured