Hi to all! I'm writing a simple simulation program for elevators but i get a problem, namely:

elevator.cpp: In constructor `Elevator::Elevator(int)':
elevator.cpp:41: error: no matching function for call to `Button::Button()'
elevator.cpp:10: note: candidates are: Button::Button(const Button&)
elevator.cpp:16: note:                 Button::Button(int, bool)
elevator.cpp:41: error: no matching function for call to `Button::Button()'
elevator.cpp:10: note: candidates are: Button::Button(const Button&)
elevator.cpp:16: note:                 Button::Button(int, bool)
elevator.cpp:44: error: `Buttonset' undeclared (first use this function)
elevator.cpp:44: error: (Each undeclared identifier is reported only once for each function it appears in.)
elevator.cpp:45: error: no match for 'operator=' in '((Elevator*)this)->Elevator::Alert = (((Button*)operator new(8u)), (<anonymous>->Button::Button(3, 0), <anonymous>))'
elevator.cpp:10: note: candidates are: Button& Button::operator=(const Button&)

The code that produces this minor irritation is the constructor of the 2nd class:

class Button {
      private: 
               enum Types {inside, outside, alarm};
               Types type;
               bool active;
      public:
               Button(int typ, bool state) {
                      if (typ!=1 && typ!=2 && typ!=3)
                                 throw ("Crappy button type in initialisation...Terminating.");
                      if(state!=0 && state!=1)
                                  throw("Boolean expected in button class initialisation... Terminating.");
                      type = Types(typ-1);
                      active = state;
               }
                      
               inline bool is_active(void) { return active; };
               inline int  who(void) { return type; };
               inline void flashb(void) { active=!active; };
               inline void press(void) { active = 1; };
};
class Elevator {
      private:
              int number;
              Button ButtonSet[10];
              Button Alert;
              queue<int> queue;
              int last_stop;
              enum Status { moving, idle, alert };
              Status stats;
      public:
             Elevator(int num) {
                          number = num;
                          for(int i=0; i<10; i++)
                                  Buttonset[i] = new Button(1, 0);
                          Alert = new Button(3, 0);
                          stats = Status(1);
             };
             void pressb (int num);
             void emergency(void);
             inline void set_stats(int status) { stats = Status(status-1); } ;
             inline int  get_stats(void) { return (int)stats; };
             int move(void);
};

I would be thankful if somebody shares an idea of the possible error!

Recommended Answers

All 5 Replies

You don't have a default constructor for Button.

Also:

ButtonSet[i] = new Button(1, 0);

You need a pointer with new.

You're trying to create objects of type Button, but don't have the constructors to match. Remember that if you provide your own constructor within a class, then you do not get a default constructor.

You also seem to have other problems - you can't assign an int to an object of an enumerated type. eg,

stats = Status(1);

this needs to be

stats = idle;

Default constructor i don't need in this case, because i need to set up some predifined values for buttons and states. I'm still a bit confused how to edit my code so it's working, though. As for the

stats = Status(1);

maybe it's an error but i haven't done any C++ programming in quite a while and also the compiler doesn't recognize it as an error. Until the testing comes a lot of code is to be written but the pebble in the shue is still there..

Without the default constructor, you can't do this:

Button ButtonSet[10];

Perhaps you meant this:

Button *ButtonSet[10];
Button *Alert;

---

Or perhaps this for a default constructor?

Button(int typ = 1, bool state = 0) {

Perhaps the second :-) Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.