I Need Help With Member Accessors.

This is a discussion on I Need Help With Member Accessors. within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream.h> class Cat { public: int GetAge(); void SetAge(int Age); int GetWeight(); void SetWeight(int Weight); int Meow(); private: ...

  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, 09:18 PM
  2. Replies: 2
    Last Post: 04-19-2008, 01:06 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  5. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 12:14 PM

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