Question

I was trying to acomplish something similar to Java "super" call which i thought would be possible in this way :

public ref class base {

public: base(){}

protected: virtual void funct()
{
   MessageBox::Show("base funct");
}
};

public ref class derived : public base
{
public: derived() : base(){}

protected: virtual void funct() new
{
((Base^)this)->funct();
///some work
}
};

But it gives me "Candidate function(s) not accesible" error. Doesn't "protected" modifier gives acces to base class elements to all its subclasses? I dont know if it makes any difference but Base class method that i want to override is inherited by Base aswell.

Was it helpful?

Solution

Your syntax is incorrect, you can call base functions like this.

base::funct();

It complains because, after the cast, you have an instance of base. The funct() function is protected, therefore you can't call it on a given instance of base.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top