Initialization of constant pointer reference member variable
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 7 of 7

Thread: Initialization of constant pointer reference member variable

Threaded View

  1. #1
    Join Date
    Feb 2009
    The milky way -> Earth -> Asia -> India -> Kerala -> Thrissur -> Eravu :)

    Exclamation Initialization of constant pointer reference member variable

    I've created an application in VC++ 6.0. Pls see the code below.

    class TestClass{
        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.

    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 06: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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center