how can I forbit inheritance?

C

Chameleon

In my library, I have classes's members which are not virtual and I want
to forbit inheritance for these members.
Is this possible?

Something like "final" keyword in java.


class A {
void member();
}

class B : public A {
void member(); // I want a fatal compile error here
}
 
D

dasjotre

Chameleon said:
In my library, I have classes's members which are not virtual and I want
to forbit inheritance for these members.
Is this possible?

Something like "final" keyword in java.


class A {
void member();
}

class B : public A {
void member(); // I want a fatal compile error here
}

check FAQ.
 
G

Geo

Chameleon said:
In my library, I have classes's members which are not virtual and I want
to forbit inheritance for these members.
Is this possible?

Something like "final" keyword in java.


class A {
void member();
}

class B : public A {
void member(); // I want a fatal compile error here
}

Why ?
 
B

blairuk

No you can't do it in C++. Perhaps leave a comment for other
developers.

ps: Why are some people so unhelpful?
 
F

Frederick Gotham

Chameleon:
In my library, I have classes's members which are not virtual and I want
to forbit inheritance for these members.
Is this possible?


class MyClass { /* Don't inherit from this! */

};
 
G

Geo

No you can't do it in C++. Perhaps leave a comment for other
developers.

ps: Why are some people so unhelpful?

Who did you think was unhelpful ?

The o/p was obviously too lazy to look in the FAQ, which covers this
quite well, and I have still to see any valid reason anyone would want
to impose this restriction anyway !
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

>
are you sure?

Since you top-posted (fixed now) it's hard to determine whether your
reply was to the fact that it's possible to make classes un-inheritable
or to the fact that some people post incorrect answers already answered
in the FAQ. However the answers to both those questions can be found in
the FAQ, section 23.11 "How can I set up my class so it won't be
inherited from?". In another section it also states that you should not
top-post, but finding that is left as an exercise.
 
B

blairuk

I am not sure what top-posting is but I believe the original question
was about stopping class members from being overridden as opposed to
stopping a class from being inherited from. Or at least that's how I
read it and I suspect most people did. Yes it's covered in the FAQ but
in section 23.12.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top