Well, I'm currently wondering why this piece of C++ code doesn't want to compile :
main.cpp
#include <iostream>
#include "box.h"
int main()
{
std::cout << "Hello World !" << std::endl;
Box *bx = new Box(4,8,40,40);
bx->hello();
return 0;
}
box.h
#ifndef BOX
#define BOX
class Box
{
public:
Box(int x, int y, int w, int h);
void hello();
private:
int box_x;
int box_y;
int box_w;
int box_h;
};
#endif
box.cpp
#include "box.h"
Box::Box(int x,int y, int w, int h)
{
box_x = x;
box_y = y;
box_w = w;
box_h = h;
}
void Box::hello()
{
std::cout << "Hello from C++ !" << std::endl;
}
The compiler keeps saying that :
/tmp/ccXu8pjM.o: In function
main': main.cpp:(.text+0x59): undefined reference to
Box::Box(int, int, int, int)' main.cpp:(.text+0x69): undefined reference to `Box::hello()' collect2: error: ld returned 1 exit status Compilation failed.