Thread: my doggy class

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    266

    my doggy class

    i have a basic problem, why when i use this class, i cant get it to use the class function, getage()?
    Code:
    #include <iostream>
    #include <conio.h>
    using namespace std;
    
    class dog
    {
          public:
          dog(int iage);
          ~dog();
          void bark();
          int getage();
          void setage(int age);
          private:
          int dogage;
    };
    
    dog::dog(int iage)
    {
                 dogage= iage;
    }
    dog::~dog()
    {
    }        
    
    void dog::bark()
    {
                cout << "\n woof";
    }
    
    int dog::getage()
    {
        return dogage;
    }
    void dog::setage(int age)
    {
         dogage=age;
    }
    
    int main(){
        dog anakin(5);
        anakin.bark();
        anakin.getage();
        getch();  
    }

  2. #2
    Registered User
    Join Date
    Mar 2005
    Posts
    140
    getage() doesn't print the age it just returns it.
    either set it to a variable and do something with it, or just print it
    Code:
    cout << anakin.getage() << endl;

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    266
    yes that worked, thanks spydoor

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  2. Specializing class
    By Elysia in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2008, 04:30 AM
  3. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM