Thread: question about Microsoft C++ 6

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    12

    question about Microsoft C++ 6

    ok I am still new with c++ and the whole interface and code and everything, but i just created 1 base class with 3 derived classes and 1 .cpp source file and everything is coded and i compiled all 4 cpp files and all came up with no errors, my question is if i coded it right i could start coding the main, and depending if i put the right code in it "technically" work fine? I think i asked this in the right way...

    Hobbes

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    erm, if I understand correctly, you're basically asking: "if I coded it right, will it work"

    the answer is "yes" to that... but I doubt that's what you were trying to get at...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    When you are working with an IDE ("interface and code and everything") your .cpp files go in your Project list (they are not #include'd into the main), and then the class declaration goes in a .h which is #include'd into the files requiring that class (like derived requiring base).

    Code:
    ////////main.cpp
    #include "main.h"
    
    BaseClass::BaseClass() //constructor to class from main.h
    {
    }
    
    int main ()
    {
    }
    
    ////////main.h
    class BaseClass
    {
    public:
      BaseClass(); //constructor declared here, defined in main.cpp
    };
    
    ////////derived1.cpp
    #include "main.h"
    
    class Derived1 : public BaseClass /*you could put this part in its own .h too, and include it into this .cpp file*/
    {
    public:
      Derived1(); //constructor
    
    };
    
    Derived1::Derived1 ()
    {
    }
    And your Project list would be: main.cpp, derived1.cpp, derived2.cpp, etc. If that compiles, then yah the code would be right.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    12
    ok well what i got is in my workspace: Under source Files - building.cpp, business.cpp, home.cpp, main.cpp, school.cpp, and under Header files: building.h(base class) business.h, home.h, school.h(all derived classes), im just following this book that i bought and that is how the code is in the book, i dunno if this way is good or not, but all cpp file compiled with no errors and no warnings, i should look for a different book...

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    >in my workspace: Under source Files - building.cpp, business.cpp, home.cpp, main.cpp, school.cpp, and under Header files: building.h(base class) business.h, home.h, school.h(all derived classes),

    Sounds reasonable so far. Now use main.cpp to act as a driver program to see if the functionality of the other classes is intact. To do that add lines like:
    Code:
    #include <iostream>
    #include "building.h"
    #include "business.h"
    #include "home.h"
    #include "school.h"
    
    int main()
    {
       building building1;
       business business1;
       home home1;
       school school1;
       
       building1.display();
       business1.display();
       home1.display();
       school1.display();
    }
    This assumes that the classes all have some default data that can be displayed calling a public accessor method called display() that is overloaded for each class. My preference, however, is to build the driver program to test each new function I add to each class along the way. That way I only have to debug a few things at a time, hopefully, rather than trying to figure out a multitude of bugs before I can test out functionality in addition to syntax.
    You're only born perfect.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  3. Retaliation towards witch king\microsoft
    By Koshare in forum Linux Programming
    Replies: 7
    Last Post: 10-19-2001, 04:54 AM
  4. I Love Microsoft
    By Witch_King in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 08-25-2001, 12:07 PM