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

Reset to default

You Might Also Like