Compile-time check for virtual function existence in derived class

M

Marco Segurini

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.
 
T

Tomas Restrepo \(MVP\)

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?
 
M

Marco Segurini

Tomas said:
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.
 
R

Ronald Laeremans [MSFT]

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

Ronald Laeremans
Visual C++
 

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

Top