0

I was wondering if anyone could help me out with this - I'm only new to C++ and it's causing me a fair amount of troubles. I'm trying to replicate a tutorial this is my test.cpp file

#include <iostream>
#include "cat.h"
using namespace std;

int main()
{
   speak();
}

this is my header file "Cat.h"

#ifndef CAT_H_INCLUDED
#define CAT_H_INCLUDED

void speak();


#endif // CAT_H_INCLUDED

this is my function declaration file Cat.cpp

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

using namespace std;

void speak()
{
  cout << "meowwww" << endl;
}

But when I update my test.cpp file like this its working but in the original tutorial the tutor didn't add the source file in the test file

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

using namespace std;
int main()
{
   Cat cat1;
   cat1.speak();
   return 0;
 }
  • How do you compile your code? – Yksisarvinen Mar 09 '22 at 13:03
  • 1
    You are not compiling and linking the `Cat.cpp` file. Add it to the list of files to compile wherever you added `test.cpp` in the same way. – user17732522 Mar 09 '22 at 13:03
  • Also, where and why did you copy that closure header from? – user17732522 Mar 09 '22 at 13:05
  • Is this a typo or did you really use "#include "cat.h" with lower-case "c" in main.cpp? – Durmus Mar 09 '22 at 13:13
  • If you are using VSCode remember that it only builds the active file by default. To build all the files in the folder you need to edit your tasks.json according to the VSCode documentation. – drescherjm Mar 09 '22 at 13:31
  • ***I was wondering if anyone could help me out with this*** You have to explain how you are building for anyone to help. If you give little or no details we can't help as we don't have access to your computer. There are many different IDEs and methods to build c++ code on several different operating systems and using several different compilers. Your basic problem is `Cat.cpp` does not appear to be used. – drescherjm Mar 09 '22 at 13:37
  • I'm using CodeBolcks as my IDE and MingGW s my compiler. I don't know how to link the file – Senura Hansaja Mar 09 '22 at 17:58

0 Answers0