Thread: Inheritance - expected class name before error

  1. #1
    Registered User
    Join Date
    Dec 2015
    Posts
    92

    Inheritance - expected class name before error

    After searching through google and not being able to fix the problem, I decided to ask here.

    So I am trying to implement inheritance, but unfortunately I am getting compiler error:

    Code:
    ControllerJoystickMode.h:7:1: error: expected class-name before '{' token
    I read on stackoverflow: "That sort of error is usually caused by the type not being defined when you try to use it."
    So I tried to forward declare classes by adding
    Code:
    class JoystickMode;
    in ControllerJoystickMode.h
    , and
    Code:
    class ControllerJoystickMode;
    , in JoystickMode.h
    , but that didn't help either.

    JoystickMode.h
    Code:
    #ifndef _JOYSTICK_MODE_H_
    #define _JOYSTICK_MODE_H_
    
    #include "Joystick.h"
    #include "Arduino.h"
    
    
    class JoysticMode 
    {
        public:
            virtual String toString(void) = 0;
            virtual void handle(void) = 0;
    };
    
    #endif
    ControllerJoystickMode.h
    Code:
    #ifndef _CONTROLLER_JOYSTICK_MODE_H_
    #define _CONTROLLER_JOYSTICK_MODE_H_
    
    #include "JoystickMode.h"
    
    class ControllerJoystickMode : public JoystickMode
    {
        public:
            String toString(void);
    };
    
    #endif

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,657
    > class JoysticMode
    ...
    > public JoystickMode
    Check your spelling 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.

  3. #3
    Registered User
    Join Date
    Dec 2015
    Posts
    92
    Quote Originally Posted by Salem View Post
    > class JoysticMode
    ...
    > public JoystickMode
    Check your spelling perhaps?

    I haven't even noticed it. Thank you Salem, I knew that it was something simple.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing reference to derived class, where base class is expected
    By a.mlw.walker in forum C++ Programming
    Replies: 28
    Last Post: 01-06-2015, 01:40 PM
  2. Replies: 8
    Last Post: 01-13-2008, 05:57 PM
  3. error: expected class-name before { token
    By keira in forum C++ Programming
    Replies: 8
    Last Post: 12-21-2007, 06:13 PM
  4. Replies: 4
    Last Post: 11-24-2007, 06:49 PM
  5. C++: Class Inheritance sytanx error (Easy)
    By Bird Killer in forum C++ Programming
    Replies: 4
    Last Post: 08-18-2006, 05:18 PM

Tags for this Thread