Thread: ^^ help me solve the error

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    4

    Thumbs up ^^ help me solve the error

    this coding i copy from book got many error hope some one can help me solve the error
    <code>
    #include <iostream.h>
    class Inner
    { int data;
    public:
    char id;
    void set (int x){ data= x;}
    Inner (int x): data(x) {}
    };
    class Outer
    { Inner room;
    public:
    float (total);
    Outer (int, char);
    void set (int i, char id){
    room.set(i); // cannot do room.data = I;
    room.id =id;
    };
    Outer::Outer (int i, char id): room(i)
    {room.id = id;}
    main( )
    { Outer collect (10, 'A’);
    collect.set(10, 'B'); // cannot do collect.room.id ='B'
    collect.total = 0.01; // no problem with this
    }
    </code>

  2. #2
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    Your ending braces don't match up properly. This is what you want
    Code:
    #include <iostream.h>
    
    class Inner
    { 
        int data;
    public:
        char id;
        void set (int x){ data= x;}
        Inner (int x): data(x) {}
    };
    
    class Outer
    { 
        Inner room;
    public:
        float (total);
        Outer (int, char);
        void set (int i, char id){
            room.set(i); // cannot do room.data = I;
            room.id =id;
        }
    };
    
    Outer::Outer (int i, char id): room(i)
    {room.id = id;}
    
    int main()
    { 
        Outer collect (10, 'A');
        collect.set(10, 'B'); // cannot do collect.room.id ='B' 
        collect.total = 0.01; // no problem with this
    }

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    room.set(i); // cannot do room.data = I;
    That is because data is a private member of your Inner class.
    collect.set(10, 'B'); // cannot do collect.room.id ='B'
    Again, your room data member is declared to be private by default within the Outer class so you cannot access it directly from within the main function.

    Put everything under the public heading if you really need to do this.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM