Initialization list of members with attributes from another class (inheritance)

Asked

Viewed 10 times

0

I know a member startup list declares and at the same instant initializes such an attribute(s), that’s what I know so far.

In the following code:

#include <iostream> // std::cout


class Foo {
public:
    const int intNum;
};


class Bar: public Foo {
public:
    Bar( int x ): IntNum( x ) {}
};


int main()
{
    Bar bar( 1 );
    
    std :: cout << bar.intNum << "\n";
    
    
    return 0;
}

I was trying to initialize the attribute intNum who now belongs to the class Bar for having inherited from Foo, then if intVar became Bar Why was there a mistake trying to initialize? What’s wrong with the code?

1 answer

0

What’s the mistake? This would be important to include in the question.

I see that you stated intNum with lowercase "i" in the parent class, but are trying to initialize Intnum (with uppercase "I" in the daughter class.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.