Professional Documents
Culture Documents
Lecture 9 - Static, Const and This Pointer
Lecture 9 - Static, Const and This Pointer
Lecture 8
Static, const and this Pointer
Awais Ali
Quiz-03
• Implement a class Plane with the following properties:
122
123 return 0;
count back to zero.
124 }
Compiling...
Fig07_01.cpp
d:fig07_01.cpp(14) : error C2662: 'setHour' : cannot convert 'this'
pointer from 'const class Time' to 'class Time &'
Conversion loses qualifiers
d:\fig07_01.cpp(20) : error C2662: 'printStandard' : cannot convert
'this' pointer from 'const class Time' to 'class Time &'
Conversion loses qualifiers
Time5.cpp
Error executing cl.exe.
public:
Something()
{
m_nValue = 0;
m_dValue = 0.0;
m_pnValue = 0;
}
};
Member initializer syntax
class Something
{
private:
const int m_nValue;
public:
Something()
{
m_nValue = 5;
}
};
Member initializer syntax
class Something
{
private:
int m_nValue;
double m_dValue;
int *m_pnValue;
public:
Something() : m_nValue(0), m_dValue(0.0), m_pnValue(0)
{
}
};
Member initializer syntax
class Something
{
private:
const int m_nValue;
public:
Something(): m_nValue(5)
{
}
};
const (Constant) Members
128
129 return 0;
130 }