Thread: error: expected class-name before '{' token, inheritance help

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    34

    error: expected class-name before '{' token, inheritance help

    Hey,
    I tried to search and found a little, but it was not enough to help me. I am getting this error:
    Code:
    InputBox.h:8: error: expected class-name before '{' token
    but I'm pretty sure the required class definitions are included.

    here's InputBox implementation and header.

    Header:
    Code:
    #ifndef INPUTBOX_H_
    #define INPUTBOX_H_
    
    //#include <FL/Fl_Input.H>
    //#include "Widget.h"
    
    class InputBox: public Fl_Input, public Widget
    {
    	public:
    		InputBox(int, int, int, int, const char* );
    	private:
    		InputBox();
    };
    #endif /*INPUTBOX_H_*/
    Implementation:
    Code:
    #include <FL/Fl_Input.H>
    #include "Widget.h"
    #include "InputBox.h"
    
    //InputBox::InputBox(){}
    
    InputBox::InputBox(int X, int Y, int W, int H, const char *L): Fl_Input(X, Y, W, H, L)
    {
    	callback(callback_changed, this);
    }
    I get this error if I were to include Widget.h and Fl_Input.H in the InputBox.h file as well. I can't figure it out, please help me if you can. Thank you.

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Well they should definitely be included in the header rather than the .cpp file.

    Are Fl_Input and/or Widget in a different namespace?

    Are there any syntax errors in Fl_Input.h or Widget.h?

    If that doesn't help, post those headers and we'll see if there's a problem in them. BTW, try not deriving from one (and don't include the header), then try the other one and see if it's a problem with Fl_Input & Widget or just one of them.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    A missing ; at the end of the class in Widget.h perhaps?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Feb 2005
    Posts
    34
    cpjust:
    I don't think they are in different namespaces, but Fl_widget is from a toolkit called FLTK, so they might be. I am not familiar enough with namespaces to know for sure. There are no syntax errors in either of them, they will compile stand alone. This problem is happening with all of my classes that derive from another class, not matter what class they are deriving from. So i'm not sure what the problem is.

    Salem:
    Widget.h has a ; at the end of the class declaration, but thanks, good thought.

    I cannot figure this out. It seems like they should be working.

  5. #5
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Post Widget.h and we'll see if there's anything obvious there.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  2. Inheritance, istream, class datamember
    By guda in forum C++ Programming
    Replies: 4
    Last Post: 09-30-2004, 12:25 PM
  3. inheritance and performance
    By kuhnmi in forum C++ Programming
    Replies: 5
    Last Post: 08-04-2004, 12:46 PM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. Need some help on class inheritance
    By HelpMe in forum C++ Programming
    Replies: 1
    Last Post: 05-21-2002, 03:44 PM