By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,367 Members | 2,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,367 IT Pros & Developers. It's quick & easy.

how can I forbit inheritance?

P: n/a
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
}
Nov 16 '06 #1
Share this Question
Share on Google+
13 Replies


P: n/a

Chameleon wrote:
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.

Nov 16 '06 #2

P: n/a
Geo

Chameleon wrote:
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 ?

Nov 16 '06 #3

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

ps: Why are some people so unhelpful?

Chameleon wrote:
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
}
Nov 16 '06 #4

P: n/a

blai...@googlemail.com wrote:
No you can't do it in C++. Perhaps leave a comment for other
developers.

ps: Why are some people so unhelpful?
Maybe they didn't know the answer.

Nov 16 '06 #5

P: n/a
dasjotre wrote:
Chameleon wrote:
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
Fatal to whom? ;-)
}

check FAQ.
Specifically, see the Creator's FAQ:

http://www.research.att.com/~bs/bs_f...#no-derivation

and this group's FAQ:

http://www.parashift.com/c++-faq-lit...html#faq-23.11

Cheers! --M

Nov 16 '06 #6

P: n/a
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! */

};

--

Frederick Gotham
Nov 16 '06 #7

P: n/a
Geo

bl*****@googlemail.com wrote:
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 !

Nov 17 '06 #8

P: n/a

bl*****@googlemail.com wrote:
No you can't do it in C++. Perhaps leave a comment for other
developers.
yes you can,
ps: Why are some people so unhelpful?
why some people post incorrect answers to
questions already covered in FAQ :->
Chameleon wrote:
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
}
Nov 17 '06 #9

P: n/a
are you sure?

dasjotre wrote:
bl*****@googlemail.com wrote:
No you can't do it in C++. Perhaps leave a comment for other
developers.

yes you can,
ps: Why are some people so unhelpful?

why some people post incorrect answers to
questions already covered in FAQ :->
Chameleon wrote:
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
}
Dec 9 '06 #10

P: n/a
On 2006-12-09 13:46, bl*****@googlemail.com wrote:
dasjotre wrote:
>bl*****@googlemail.com wrote:
No you can't do it in C++. Perhaps leave a comment for other
developers.

yes you can,
ps: Why are some people so unhelpful?

why some people post incorrect answers to
questions already covered in FAQ :->

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.

--
Erik Wikström

Dec 9 '06 #11

P: n/a
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.

Erik Wikström wrote:
On 2006-12-09 13:46, bl*****@googlemail.com wrote:
dasjotre wrote:
bl*****@googlemail.com wrote:
No you can't do it in C++. Perhaps leave a comment for other
developers.


yes you can,

ps: Why are some people so unhelpful?

why some people post incorrect answers to
questions already covered in FAQ :->
>
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.

--
Erik Wikström
Dec 11 '06 #12

P: n/a
bl*****@googlemail.com wrote:
I am not sure what top-posting is
Your replies belong following or interspersed with properly trimmed
quotes. See the majority of other posts in the newsgroup, or the group
FAQ list:
<http://www.parashift.com/c++-faq-lite/how-to-post.html>
Dec 11 '06 #13

P: n/a
Default User wrote:
bl*****@googlemail.com wrote:
I am not sure what top-posting is

Your replies belong following or interspersed with properly trimmed
quotes. See the majority of other posts in the newsgroup, or the group
FAQ list:
<http://www.parashift.com/c++-faq-lite/how-to-post.html>
Okay thanks. I had been just using the default Google Groups behavior
but will make amends.

Dec 12 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.