-
February 5th, 2009, 05:51 AM
#1
Initialization of constant pointer reference member variable
I've created an application in VC++ 6.0. Pls see the code below.
Code:
class TestClass{
public:
TestClass(); // standard constructor
const int *& m_a;
int* m_b;
};
i have two members. First one: m_a is a constant reference to pointer of int.
The next one: m_b is an int pointer.
In the constructor i've initialized the members as shown below.
Code:
TestClass::TestClass()
:m_b(0),
m_a(m_b)
{
}
Then i built it in VC++ 6.0, No errors shown, everything was fine.
Then I opened the same application in VC++ 9.0 (VS2008), It is showing a compilation error as follows.
1>d:\technical\TestClass\TestClass.cpp(66) : error C2440: 'initializing' : cannot convert from 'int *' to 'const int *&'
1> Conversion loses qualifiers
1>d:\technical\TestClass\TestClass.cpp(66) : error C2439: 'TestClass::m_a' : member could not be initialized
1> d:\technical\TestClass\TestClass.h(55) : see declaration of 'TestClass::m_a'
Why this error happens? Is there any way to solve this error? Please help....
Last edited by rageshc; February 5th, 2009 at 07:27 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|