1

so I just started learning C++ literally yesterday and thanks to some prior experience with Lua I'm catching on pretty fast. I've been doing a beginner course on it at http://courses.caveofprogramming.com/. I was trying to create a class but ran into an error.It might also be worth mentioning that the expert uses Eclipse as his EDI, while I use CodeBlocks. Here's what I have.

main.cpp

 #include <iostream>
 #include "Cat.h"

 using namespace std;

 int main()
 {
     Cat tommy;
     tommy.Grizzly() == true;
     tommy.Bark();

     return 0;
 }

Cat.cpp

#include "Cat.h"
#include <iostream>

using namespace std;

void Cat::Bark()
{
    if (Grizzly())
    {
        cout << "RUFF!!!!!!" << endl;
    }
    else
    {
        cout << ":)" << endl;
    }
}

Cat.h

#ifndef CAT_H
#define CAT_H


class Cat
{
public :
    bool Grizzly();
    void Bark();
};

#endif // CAT_H

here's the error

C:\Users\Nas\Desktop\Coding Projects\Class Members 4\main.cpp|9|undefined reference to `Cat::Grizzly()'|
Nasir Jones
  • 61
  • 1
  • 9

1 Answers1

0

You get an undefined reference error because you haven't defined Cat::Grizzly, you have just declared it.

Add a definition for the function:

bool Cat::Grizzly() {
    //implementation
}
TartanLlama
  • 63,752
  • 13
  • 157
  • 193