I've been following TheNewBoston's C++ tutorials and it went just fine until I got to placing classes in different files. I've followed the video to the letter but every time I try to build and run I get the error "undefined reference to Burrito::Burrito". The code is as follows.
#include "Burrito.h"
usingnamespace std;
Burrito::Burrito()
{
cout << "Please work. Pretty please. With a cherry on top.";
}
I just don't understand. I know from the YouTube comments that I'm not the only one who has this problem yet it worked just fine for Bucky. My compiler is Code::Blocks, but then again so is Bucky's which means that the compiler probably isn't the problem. I'd be very grateful to anyone who can figure out why the hell this is happening. Thanks in advance.
Did you create a project with main.cpp, Burrito.h, and Burrito.cpp?
Or did you just hit compile on main.cpp, hoping that the linker would be able to "magically" detect that the definition of Burrito::Burrito is in Burrito.cpp, not in main.cpp or Burrito.h?
When you start splitting your program into multiple .cpp files, you're going to need to create a project for that.
(Well, I guess you could always compile it manually over the command line, but regardless....)
Sorry, got the whole IDE/compiler thing mixed up. I'm a beginner at this, as you've probably guessed. How would I tell if they're in the same project? Thanks again for the replies.
The video doesn't show him creating the project file.
In fact, he already had it set up before he started recording that video.
If you just started out with a blank new file (no project) and then followed his instructions, you would certainly have your three files, but when you hit compile, it'll only compile main.cpp and you'll get that error.
So create a new project first (File > New > Project > Console Project) and then go from there.
Ah. You see, in the very first video he does talk about creating a new project so I've been doing that since the start. If all I needed for the files to be in the same project was to make a new Console Application then yes, my files are all in the same project.
Just to make sure, on the left side of the screen (the "Management" pane), under "Projects", you have all three files in your project?
It should look something like
Oh, I'm a complete and utter moron beyond human comprehension. You see, this isn't my first time watching these tutorials. Absolutely ages ago, I started watching them because I wanted to get into programming. I got to about the 40th video and then, for some reason or another, I stopped. I can't remember why now, various things must have just got in the way. Then a few months back I decided to get back into programming and I immediately came to Bucky's videos because they're very well done. But you see, because I'd forgotten quite a bit I decided to watch back through the tutorials until I got to where I was as a sort of refresher course. I created a new console application and started watching through them again, doing the various things as I went. Only, I saved and stopped for the day before getting back to this, which proved disastrous. You see, when you go to File > Open and open up main.cpp it doesn't open it up as a project, it just opens it up as a file. Only I didn't realize that. So when I tried to do this tutorial it didn't work because I didn't actually have a project to put the classes in, just a reused main. Inevitably, this error happened and I just couldn't find a solution, so I gave up for the time being. Then yesterday I decided to try and get back into it again the same thing happened because I was still using an unconnected main. Thank you so much for this, I understand now and I've finally got it to work. However, I have one last question: how do I open up a project and continue working on it? I can't start a new project all over again every time I don't finish something in one day.
It works! Thank you so much! It frickin' works! Ha ha! Oh my God, I spent so long trying to find an answer on the internet with absolutely no joy and then within my first few hours of being on this site I get an answer! Once again, thank you so very much! Ah, my! Now I can continue programming! Thank you!