Thread: Classes: public or private?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    249
    Well, you can do that but I don't think that there's any reason to. You don't need two of the same class...Just make one class and when you declare your class type variable, make it an array. Example:

    Code:
    class Person
    {
    public:
         int GetAge();
    private:
          int age; 
    };
    
    int Person::GetAge()
    {
           return age;
    }
    
    int main()
    {
         Person person[2]; //2 different people
         cout<<"Person 1's age: "<<person[0].GetAge();
         cout<<"Person 2's age: "<<person[1].GetAge();
    
         return 0;
    }
    Last edited by funkydude9; 08-18-2003 at 09:18 PM.
    Well, there are a few things wrong with your code:

    1) It does not work.
    2) It does not work.
    3) It does not work.

    Hope this helps.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. webBrowser problem
    By algi in forum C# Programming
    Replies: 7
    Last Post: 08-19-2005, 09:35 AM
  2. Problem with character arrays in classes
    By spoketoosoon in forum C++ Programming
    Replies: 3
    Last Post: 03-16-2004, 03:57 AM
  3. Need help with calculator program
    By Kate in forum C# Programming
    Replies: 1
    Last Post: 01-16-2004, 10:48 AM
  4. program to unpack packed data
    By vsk in forum C Programming
    Replies: 5
    Last Post: 11-14-2002, 09:17 PM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 01:26 PM