user2753948
user2753948

Reputation: 31

copy constructor problem with const attribute

class exemple{
const int a

exemple(exemplec const &item){
}

};

I need to make a copy constructor for a project with a const attribute, I don't have a cloue how to make it.

Upvotes: 0

Views: 129

Answers (1)

masoud
masoud

Reputation: 56479

Do as below, make the copy-constructor public, fix a typo, copy the member's value.

class exemple
{
    const int a;
  public:    
    exemple(exemple const &item) : a(item.a) {}
};

You can initialize constant member using initializer list like the code.

Upvotes: 2

Related Questions