This is my first ever C++ project. I have 1600 lines of code mostly in include files using FLTK widgets and I would like to split the class definitions and the code the way I always see recommended. I have tried numerous times to figure out what goes where and I always get compiler errors.
I've been trying with some example code, below. All I need it to do is compile and show me a window.
main.cpp
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include "mybox.h"
int main(int argc, char *argv[]) {
Fl_Window *w = new Fl_Window(100, 100, 300, 300);
mybox *b = new mybox(110, 110, 100, 100);
end();
b->show();
return Fl::run();
}
mybox.h
#ifndef MYBOX_H
#define MYBOX_H
#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include "mybox.h"
class mybox : public Fl_Box {
public:
mybox(int x, int y, int w, int h, const char *lbl) : Fl_Box(x, y, w, h, lbl) {}
};
#endif // MYBOX_H
mybox.cpp
#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include "mybox.h"
mybox::mybox(int x, int y, int w, int h, const char *lbl) : Fl_Box(x, y, w, h, lbl){}
I have seen many errors referencing redefinition of prototype; missing prototype; expected foo before bar, etc. Can somebody please enlighten me? -dave
You put the definition of your constructor in two places so you need to remove it from here:
class mybox : public Fl_Box {
public:
mybox(int x, int y, int w, int h, const char *lbl); // removed
};