1

I'm trying to figure out how to create a new class and access it (sorry if that's not worded right) when coding in VS Code, but I keep getting the error shown below:

main.obj : error LNK2019: unresolved external symbol "public: __thiscall Burrito::Burrito(void)" (??0Burrito@@QAE@XZ) referenced in function _main

How can I create a new class for C++ and access it in VS Code?

all three files are shown here

Also, here are my code files as text:

// main.cpp
#include <iostream>
#include "Burrito.h"
using namespace std;

int main()
{
    Burrito bo;
    return 0;
}


// Burrito.h
#ifndef BURRITO_H
#define BURRITO_H
#include <iostream>
#include <string>
using namespace std;

class Burrito
{
    public:
        Burrito();
};
#endif


// Burrito.cpp
#include "Burrito.h"
#include <iostream>
using namespace std;

Burrito::Burrito()
{
    cout << "hi people" << endl;
}
zoheezus
  • 35
  • 1
  • 7
  • 4
    Are you sure you have added the Burrito.cpp file to your project? – Dmitry Kuzminov May 21 '19 at 23:22
  • @DmitryKuzminov Yes, atleast I think so. All the files are in the same folder. – zoheezus May 22 '19 at 01:05
  • Please provide us a screenshot of your project. – Dmitry Kuzminov May 22 '19 at 01:56
  • @DmitryKuzminov I've edited the post. There is now a link to a screenshot with all three files open and the error message. – zoheezus May 22 '19 at 02:17
  • What are you selecting to compile and run the program? If you are right clicking the main.cpp and selecting something from the pop up menu it only applies to main.cpp. If you are typing the command directly into the terminal then the command you are typing only includes main.cpp. You need to compile and run both cpp files but how you do that depends on how you are doing it now. – Jerry Jeremiah May 22 '19 at 04:12
  • @JerryJeremiah Yes, thank you. That's it. – zoheezus May 22 '19 at 16:43

2 Answers2

1

You are not actually linking Burrito.cpp with the rest of your code, and you may not even be compiling it (if you add random garbage to Burrito.cpp, do you get errors?)

The precise way of doing that will depend on what build system you're using, which you haven't specified.

Brennan Vincent
  • 10,736
  • 9
  • 32
  • 54
0

From what I can see on your screenshot, the only source file you provide to the compiler is main.cpp. Try to provide both (all) your source files: cl main.cpp Burrito.cpp

Dmitry Kuzminov
  • 6,180
  • 6
  • 18
  • 40