M
M
MrJeos2013-06-02 18:21:50
C++ / C#
MrJeos, 2013-06-02 18:21:50

Preventing an ancestor constructor from being called. How?

Hello. Got a question. To get started, sample code:

class BaseC
{
    public BaseC()
    {
        // Do something
    }
}
class DerivedC : BaseC
{
    public DerivedC()
    {
        // Some code
    }
}

When a constructor of a descendant is called, the constructor of the ancestor is automatically called. How to prevent it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
groaner, 2013-06-02
@groaner

No way. If the ancestor constructor fails, the object will not be fully initialized. Why do you need a half-created object?

F
FilimoniC, 2013-06-02
@FilimoniC

Convert the class to an interface if possible. If you have a class that doesn't require initialization, then it's not really a class.
I don't know C# so I can't really help.

A
Alexey, 2013-06-02
@Renzo

No, that's the concept of OOP

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question