C++ "Classes in separate files"

+3 Cardinal Coog · January 12, 2015
I keep getting the error: "undefined reference to burrito::burrito()"

Here is the main file.

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

using namespace std;

int main()
    burrito bo;

    return 0;

Here is the Header file:
#ifndef BURRITO_H
#define BURRITO_H

class burrito


#endif // BURRITO_H

Here is the Class file:

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

using namespace std;

    cout << "I'm getting hungry." << endl;

Post a Reply


- page 2
Oldest  Newest  Rating
0 Cardinal Coog · January 13, 2015
Thanks for the try. That's a very wise suggestion.  But, sadly, no that did not solve the problem.

I even recreated all new files and made sure the "add paths to project and use relative path" options were unchecked. I also have "virtual destructor" and "has destructor" unchecked.

Again, nice try...
0 Cardinal Coog · January 13, 2015
I tried replying to your suggestion earlier, but it never appeared. Sorry, if post appears twice. Anyway...

Nice try. But, unchecking "add paths to project and use relative path" did not solve the problem.

I also have "virtual destructor' and "has destructor" unchecked.

Again, good thought.
0 Vikash Kumar Bijarnia · January 13, 2015
Try in a new project..totally new project ..and create the new class like this..i had the same problem..but after unchecking those two things ..my code worked.
0 Cardinal Coog · January 13, 2015
C Student: it works from command line. I coded a new set of files substituting "Color" with "Cheese".

Compiled with:

g++ main.cpp Cheese.h Cheese.cpp -o myProgram

Executed with:



My favorite cheese is cheddar.

Pretty cheesy, huh?;)

Not sure what happened with Code Blocks, but I guess I might have inadvertently changed something. Will reinstall later.

Thanks to everyone for your help!:)
+1 Scott Walker · May 7, 2015
This is not an issue with code or compiler, this is an issue with Code::Blocks.

To fix, simply save your project and exit Code::Blocks. Then re-open Code::Blocks and open the project.

I know this was probably too late for this post but for future reference :-)
  • 1
  • 2



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator