Thread: I Need Help With Member Accessors.

  1. #1
    Registered User DeanDemon's Avatar
    Join Date
    Nov 2002
    Posts
    37

    Unhappy I Need Help With Member Accessors.

    Code:
    #include <iostream.h>
    class Cat
    {
    public:
    int GetAge();
    void SetAge(int Age);
    int GetWeight();
    void SetWeight(int Weight);
    int Meow();
    private:
    int itsAge;
    int itsWeight;
    };
    int Cat::Meow()
    {
    cout << "\nMeow!";
    }
    int main()
    {
    Cat Frisky;
    Frisky.SetAge(5);
    Frisky.Meow();
    cout << "Frisky is a cat who is " ;
    cout << Frisky.GetAge() << " years old.\n";
    Frisky.Meow();
    return 0;
    }
    When this code is compiled, I get these errors:

    "Undefined reference to Cat::SetAge"
    "Undefined reference to Cat::GetAge"

    I looked into the problem, tried fixing it, only to encounter many more errors. Can somebody please help?

    Thanks.


    &#91;code]&#91;/code]tagged by Salem

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    You're getting the error because you declared the member functions and called them but you never defined what they do.

    This is a link error not a compile error.

    Also, don't forget to return a value from meow since you declared it with an int return type!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Replies: 2
    Last Post: 04-19-2008, 12:06 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  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. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM