Vs Code Is Not Linking My. Cpp Files with the Main. Cpp File When I Try to Compile It and Changing the User Settings. Json in vs Code Is Not Fixing It [Duplicate]

I am using Windows. I can't get VS Code to link the class .cpp file with the main.cpp file when I compile it.

This works:

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

using namespace std;

Burrito::Burrito(){
    b = 0;
    cout << "This is a default" << endl;
}

Burrito::Burrito(int b){
    this->b = b;
    cout << "This is parameterized " << endl;
}

int main(){
    Burrito bo;
    cout << bo.b << endl;

    Burrito* b;
    b = new Burrito(2);
    cout << b->b << endl;

    return 0;
}

This does not work:

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

using namespace std;


int main(){
    Burrito bo;
    cout << bo.b << endl;

    Burrito* b;
    b = new Burrito(2);
    cout << b->b << endl;

    return 0;
}

I've found similar problems that say to go into the User settings.json and make this change:

"code-runner.executorMap": {
        "cpp": "cd $dir && g++ *.cpp -o $fileNameWithoutExt && $fileNameWithoutExt.exe"
    }

I'm still getting this error:

C:\Users\joe\OneDrive\Documents\collegepractice\programs\bp/main.cpp:12: undefined reference to `Burrito::Burrito(int)'

I also made this change and got the same issue.

I'm a sysadmin who is going back to school next semester trying to get practice with C++ so I apologize if this isn't enough good info. If you need more I am happy to provide it.

burrito.cpp:

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

using namespace std;

Burrito::Burrito(){
    b = 0;
    cout << "This is a default" << endl;
}

Burrito::Burrito(int b){
    this->b = b;
    cout << "This is parameterized " << endl;
}

burrito.h:

#ifndef BURRITO_H
#define BURRITO_H


class Burrito
{
    public:
        int b;
        Burrito();
        Burrito(int b);
};

#endif
9
David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest