Given this class declaration in my CLamp.h file:
Code:
class CLamp: public CSwitch, public CBulb
{
public:
CLamp(int x = 0); // constructor that will construct the lamp with x watts
CLamp(const CLamp &original); // copy constructor
void on(void); // turn switch and bulb on
void off(void); // turn switch and bulb off
void print(void); // print the state of the lamp
int getpower(void); // return power currently used by the lamp
~CLamp(void); // destructor
};
When working on my copy constructor indicated below:
Code:
CLamp::CLamp(const CLamp &original)
{
// make a hard copy of CBulb variables
setwatts(original.getpower());
if(original.getstate())
{
CBulb::on();
}
else
{
CBulb::off();
}
// make a hard copy of CSwitch variables
if(original.getswitchstate())
{
close();
}
else
{
open();
}
}
When I compiled my code, I am having the error about pointer conversion error when i used the original accessor methods to make hard copies of CLamp. Below shows the error message:
Code:
--------------------Configuration: lab1_q1 - Win32 Debug--------------------
Compiling...
CLamp.cpp
G:\lab1_q1\CLamp.cpp(23) : error C2662: 'getpower' : cannot convert 'this' pointer from 'const class CLamp' to 'class CLamp &'
Conversion loses qualifiers
G:\lab1_q1\CLamp.cpp(24) : error C2662: 'getstate' : cannot convert 'this' pointer from 'const class CLamp' to 'class CBulb &'
Conversion loses qualifiers
G:\lab1_q1\CLamp.cpp(34) : error C2662: 'getswitchstate' : cannot convert 'this' pointer from 'const class CLamp' to 'class CSwitch &'
Conversion loses qualifiers
Error executing cl.exe.
Creating browse info file...
lab1_q1.exe - 3 error(s), 0 warning(s)
I have no idea what is going on with the pointer conversion. Any comments would be much appreciated.