+ Reply to Thread
Results 1 to 2 of 2

Thread: What is must be initialized in constructor base/member initializer list error?

  1. #1

    What is must be initialized in constructor base/member initializer list error?

    Following program just raises compiler time error.

    Code:
    class CConstData
    {
    private:
    	const int m_data ;
    public:
    	CConstData(int data)
    	{
    		m_data = data ;
    	}
    } ;
    How to resolve this issue?

  2. #2
    Whenever you declared any const member in the class, you should use class initialization list to initialize them.

    Following should resolve your issue:

    Code:
    class CConstData
    {
    private:
    	const int m_data ;
    public:
    	CConstData(int data) : m_data(data)
    	{
    		
    	}
    } ;
    Hope this help resolving your issue.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts