my doggy class

This is a discussion on my doggy class within the C++ Programming forums, part of the General Programming Boards category; i have a basic problem, why when i use this class, i cant get it to use the class function, ...

  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, 05:30 AM
  3. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 02:03 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21