0

I have slimmed down everything to barebones and still getting the same errors. I now have just my constructor and still got an error: main.cpp:7: undefined reference to `MyThing::MyThing ()'

Any help would be much appreciated. My code:

MyThing.h

#ifndef MYTHING_H
#define MYTHING_H
class MyThing
{
  public:
    MyThing();
};
#endif

MyThing.cpp

#include "MyThing.h"
using namespace std;         
    
MyThing::MyThing(){}

main.cpp

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

using namespace std;
int main()
{   
    MyThing lt;
    return 0;
}
  • 3
    Include your build command(s) [in your question](https://stackoverflow.com/posts/71609807/edit). – WhozCraig Mar 24 '22 at 21:45
  • 1
    You probably did not compile `MyThing.cpp` If you are using VSCode that is understandable since the default behavior of the c++ support in the IDE is to build only the active file. The documentation explains what change to make to the tasks.json to build more than 1 source file. – drescherjm Mar 24 '22 at 21:45
  • I like how you never forget to write `using namespace std;` – MatG Mar 24 '22 at 21:48
  • @drescherjm you were spot on, I am using VS Code and did need to adjust my launch.json and tasks.json. Many thanks for all. Apologies for coming back after so long, really did not expect such a prompt response from all. – Tristan Margot Mar 25 '22 at 17:03

0 Answers0