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
{
    public:
        burrito();

};

#endif // BURRITO_H

Here is the Class file:

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


using namespace std;

burrito::burrito()
{
    cout << "I'm getting hungry." << endl;
}



Post a Reply

Replies

- page 2
Oldest  Newest  Rating
0 Alam Khattak · January 12, 2015
/images/forum/upload/2015-01-12/27876e35d36be80bbf459878a20aeabb.jpg/images/forum/upload/2015-01-12/43cab9c798f8006211fe2a3a117eb309.jpg/images/forum/upload/2015-01-12/5f717ef013a5010cf98a86268e111b05.jpg/images/forum/upload/2015-01-12/b46f54562f6e3756e0e049f9493cb51e.jpg
+1 Cardinal Coog · January 12, 2015
UGH... Same error in Linux. Using C:B 13.12 Build: Jan 27 2014 - wx2.8.12
(Linux, unicode) - 32 bit

"undefined reference to burrito::burrito()":'(

BTW, the compiler is set to keep the files in the same directory.
+1 Cardinal Coog · January 12, 2015
I'm using C:B 13.12 Build: Dec 27, 2013

I tried re-writing the code and now I'm getting "undefined reference to 'winMain@16'.
In a few minutes I'll try it in my Linux box and let you know what happens. Would still like to know though :(
0 Jay Bennett · January 12, 2015
There is nothing wrong with your code (as far as I can see), and it works. I tested your exact code in both Code::Blocks (version "svn build rev 10035") and Visual Studio 2013. Not sure why you are getting that error, maybe try creating a new project and try the code again?
0 Alf Nohr · January 12, 2015
hmm, it's working for me. What compiler are you using?

Undefined reference error, usually  appears  because the .o file "which gets created from the .cpp file"  do not exist, and your compiler is not able to link them.
  • 1
  • 2

C++

126,465 followers
About

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

Links
Moderators
Bucky Roberts Administrator