| | |
Error in class constructor
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Hi to all! I'm writing a simple simulation program for elevators but i get a problem, namely:
The code that produces this minor irritation is the constructor of the 2nd class:
I would be thankful if somebody shares an idea of the possible error!
C++ Syntax (Toggle Plain Text)
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:
C++ Syntax (Toggle Plain Text)
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!
You don't have a default constructor for Button.
Also: You need a pointer with new.
Also:
C++ Syntax (Toggle Plain Text)
ButtonSet[i] = new Button(1, 0);
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
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, this needs to be
You also seem to have other problems - you can't assign an int to an object of an enumerated type. eg,
C++ Syntax (Toggle Plain Text)
stats = Status(1);
C++ Syntax (Toggle Plain Text)
stats = idle;
¿umop apisdn upside down? 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
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..
C++ Syntax (Toggle Plain Text)
stats = Status(1);
Without the default constructor, you can't do this:
Perhaps you meant this:
---
Or perhaps this for a default constructor?
C++ Syntax (Toggle Plain Text)
Button ButtonSet[10];
Button *ButtonSet[10]; Button *Alert;
---
Or perhaps this for a default constructor?
Button(int typ = 1, bool state = 0) {
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- COMException error, class not registered (VB.NET)
- Class Constructor Shorthand (C++)
- error in copy constructor (C)
- '[Class] is not abstract..' error when i use 'implements' (Java)
Other Threads in the C++ Forum
- Previous Thread: Reccomended Books and Compilers
- Next Thread: Desperate and eagar to learn!!!
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






