0

Here's a skeleton of my code -

class FLTK_win;        //class declaration before full definition so it can be used in the other class
//first of the classes
class functions {
                public:
                        void example_function();
.....
};

void example_function() {
                   std::string input = FLTK_win::Textbox->value();

/*so here I want to make a string that takes the value of whatever the user has 
entered in the text box in the FLTK window class*/
........
}

//second class which is a friend of the first
class FLTK_win : public Fl_Window {

    friend class functions;

    Fl_Input* Textbox;

......//and the rest of the stuff to open the FLTK window when an instance of the class is created
};

From this line:

std::string input = FLTK_win::Textbox->value();

I get the error:

"incomplete type 'FLTK_win' used in nested name specifier"

I'm wondering whether I have my classes in the wrong order? However I don't see how that would give this error.

Or else there must be a different (proper) way to call the value of an FLTK text box in a different class rather than "FLTK_win::Textbox->value()" ?

I have tried creating an instance of FLTK_win, called testwin within the 'functions' class and then writing:

testwin.Textbox->value();

However I think this doesn't work because the value of the textbox isn't a variable so can't be called in this way. I've also looked into getters & setters but don't understand them enough to know if they are the answer.

Thanks in advance for your help!

airdas
  • 872
  • 2
  • 11
  • 19
  • All you have in `example_function` is the name `FLTK_win`, but the compiler have no idea what's in the class. You need the complete class definition to be able to use members of the class, or the compiler will not know those members exists. – Some programmer dude Nov 30 '14 at 16:53
  • @JoachimPileborg so I should move the 'FLTK_win' class definition above the 'functions' class definition? – airdas Dec 01 '14 at 12:45

1 Answers1

0

If you wish to access the textbox, the easiest way is to put the definition before the function.

class FLTK_win: public Fl_window
{
...
    Fl_Input* Textbox;
...
};

Then declare an instance of your class

FLTK_win* awin;

In your function, you can now use it because the compiler now knows what awin is and what its member functions/variables are.

    std::string input = awin->Textbox->value();

Finally, in your main program you need to create the instance

int main()
{
    awin = new FLTK_win();
    ...
} 
cup
  • 7,589
  • 4
  • 19
  • 42