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

Compile-time check for virtual function existence in derived class

P: n/a
Hi,

Actually I am creating a hierarchy of MANAGED classes.
I like to know if there is way to mark a virtual (abstract) function as
"must be implemented on each derived class".

example:

ref class Test abstract
{
public:
void read() abstract;
};

ref class TestDerived : Test
{
public:
void read() {}
};

ref class TestDerived2 : TestDerived
{
};

int main()
{
TestDerived2^ TD = gcnew TestDerived2();

return 0;
}

I'd like a compile-error for this code considering that 'void read()' is
not implemented for 'TestDerived2' class

Thanks fon any help.
Marco.

--
For direct reply change underscore to dot

Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Marco,
Actually I am creating a hierarchy of MANAGED classes.
I like to know if there is way to mark a virtual (abstract) function as
"must be implemented on each derived class". I'd like a compile-error for this code considering that 'void read()' is
not implemented for 'TestDerived2' class


Highly unlikely I'd guess, since TestDerived is a concrete class, and thus,
what you put in is valid code (since TestDerived2 actually *does* have the
read() implementation inherited from TestDerived)

What is it that you're trying to accomplish?
--
Tomas Restrepo
to****@mvps.org
Nov 17 '05 #2

P: n/a
Tomas Restrepo (MVP) wrote:

Highly unlikely I'd guess, since TestDerived is a concrete class, and thus,
what you put in is valid code (since TestDerived2 actually *does* have the
read() implementation inherited from TestDerived)
This is the same behaviour of a standard c++ class hierarchy (not managed).
What is it that you're trying to accomplish?


I like to know if in a hierarchy of managed classes
I am able to give to a virtual/abstract member-function of the class A
an attribute or other so that I may find out (at compiler-time)
if every derived class of A implements *its own* version of this
virtual/abstract member-function.

Marco.

--
For direct reply change underscore to dot

Nov 17 '05 #3

P: n/a
No, there is not, abstract like pure in standard C++ only works on the next
level of the inheritance hierarchy.

Ronald Laeremans
Visual C++

"Marco Segurini" <ma************@jumpy.it> wrote in message
news:uz**************@TK2MSFTNGP14.phx.gbl...
Tomas Restrepo (MVP) wrote:

Highly unlikely I'd guess, since TestDerived is a concrete class, and
thus,
what you put in is valid code (since TestDerived2 actually *does* have
the
read() implementation inherited from TestDerived)

This is the same behaviour of a standard c++ class hierarchy (not
managed).
What is it that you're trying to accomplish?


I like to know if in a hierarchy of managed classes
I am able to give to a virtual/abstract member-function of the class A an
attribute or other so that I may find out (at compiler-time)
if every derived class of A implements *its own* version of this
virtual/abstract member-function.

Marco.

--
For direct reply change underscore to dot

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.