Thread: c++ class error

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    6

    c++ class error

    i made a simple Animal class but when i try to build and run the class it give me many error i can't understand where i made mistake
    Code:
    #include <iostream>
    
    
    using namespace std;
    
    
    class Animal{
        
    public:
        //class public members
        int GetAnimalAge();
        int GetAnimalWeight();
        
        void SetAnimalAge(int age);
        void SetAnimalWeight(int weight);
        
        void AnimalSound();
        
        
    private: 
        // class private members
        int animalAge;
        int animalWeight;
    };
    
    
    void Animal::GetAnimalAge(){
        return animalAge;
    }
    
    
    void Animal::GetAnimalWeight(){
        return animalWeight;
    }
    
    
    int Animal::SetAnimalAge(int age){
        animalAge = age;
    }
    
    
    int Animal::SetAnimalWeight(int weight){
        animalWeight = weight;
    }
    
    
    
    
    
    
    void AnimalSound(){
        cout << "dog barks " << endl;
    }
    
    
    
    
    int main(int argc, char **argv)
    {
    	cout << "c++ classes " << endl;
        
        // creating class object
        
        Animal Dog;
        
        Dog.SetAnimalAge(2);
        Dog.SetAnimalWeight(8);
        
        cout << "dog age is " << Dog.GetAnimalAge() << " years " << endl;
        cout << "dog weight is " << Dog.GetAnimalWeight() << " kg" << endl;
        Dog.AnimalSound();
        
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Feb 2016
    Posts
    6
    i found my error not its working

  3. #3
    Informer -Adrian's Avatar
    Join Date
    Jan 2013
    Posts
    817
    Just got mixed up with the return types, eh?

  4. #4
    Registered User
    Join Date
    Jan 2016
    Location
    India
    Posts
    4
    This is running code [You used different return types while defining functions]
    Code:
    
    
    Code:
    #include <iostream>
     
     using namespace std;
    
    
    class Animal
    {
    public:
        //class public members
        int GetAnimalAge();
        int GetAnimalWeight();
         
        void SetAnimalAge(int age);
        void SetAnimalWeight(int weight);
         
        void AnimalSound();
        
    private: 
        // class private members
        int animalAge;
        int animalWeight;
    };
     
     
    int Animal::GetAnimalAge(){
        return animalAge;
    }
     
     
    int Animal::GetAnimalWeight(){
        return animalWeight;
    }
     
     
    void Animal::SetAnimalAge(int age){
        animalAge = age;
    }
     
     
    void Animal::SetAnimalWeight(int weight){
        animalWeight = weight;
    }
     
    void Animal::AnimalSound(){
        cout << "dog barks " << endl;
    }
     
     
     
     
    int main(int argc, char **argv)
    {
        cout << "c++ classes " << endl;
         
        // creating class object
         
        Animal Dog;
         
        Dog.SetAnimalAge(2);
        Dog.SetAnimalWeight(8);
         
        cout << "dog age is " << Dog.GetAnimalAge() << " years " << endl;
        cout << "dog weight is " << Dog.GetAnimalWeight() << " kg" << endl;
        Dog.AnimalSound();
         
        return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. class error
    By manzoor in forum C++ Programming
    Replies: 6
    Last Post: 06-13-2008, 03:55 PM
  2. Replies: 7
    Last Post: 11-10-2007, 05:17 AM
  3. class error?think?
    By Hitachi in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2005, 09:26 AM
  4. Template <class T1, class T2, class T3> error LNK2019
    By JonAntoine in forum C++ Programming
    Replies: 9
    Last Post: 10-11-2004, 12:25 PM
  5. Class Error
    By LloydUzari in forum C++ Programming
    Replies: 4
    Last Post: 08-08-2004, 09:58 AM