473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

is virtual necessary when inheriting from an abstract class thatimpmlements an interface?

Suppose i have this class declaration:

public abstract class ConfigurableComponent : Component, IConfigure

if IConfigure has a method with this signature:

List<ParameterListParameters(Identity identity)

Would i need to implement it in the abstract class with as virtual in
order for it to be overrideable in a descendant class?

public virtual List<ParameterListParameters(Identity identity)

dan

Where in the docs would this kind of stuff live? I don't know how to
find this kind of theory.
Jul 17 '06 #1
2 1341
"Dan Holmes" <da*******@bigfoot.coma écrit dans le message de news:
ep**************@TK2MSFTNGP03.phx.gbl...

| Suppose i have this class declaration:
|
| public abstract class ConfigurableComponent : Component, IConfigure
|
| if IConfigure has a method with this signature:
|
| List<ParameterListParameters(Identity identity)
|
| Would i need to implement it in the abstract class with as virtual in
| order for it to be overrideable in a descendant class?
|
| public virtual List<ParameterListParameters(Identity identity)

You can either implement interface members implicitly or explicitly :

implicit

public virtual List<ParameterListParameters(Identity identity)
{
...
}

explicit

protected virtual List<ParameterListParameters(Identity identity)
{
...
}

List<ParameterIConfigure.ListParameters(Identity identity)
{
return ListParameters(identity);
}

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jul 17 '06 #2
Dan Holmes wrote:
Suppose i have this class declaration:

public abstract class ConfigurableComponent : Component, IConfigure

if IConfigure has a method with this signature:

List<ParameterListParameters(Identity identity)

Would i need to implement it in the abstract class with as virtual in
order for it to be overrideable in a descendant class?

public virtual List<ParameterListParameters(Identity identity)

dan

Where in the docs would this kind of stuff live? I don't know how to
find this kind of theory.
If you want your method to be overridable in derived classes, then yes, you
must apply the 'virtual' modifier to the method declaration. If you want
to force derived classes to override the method, then apply the 'abstract'
modifier to the method declaration.

The interface is implemented on the class to which you specify in the class
declaration, i.e. on the class ConfigurableComponent in your case. Derived
classes in order to override your implementation need to be given the
virtual method.

--
Hope this helps,
Tom Spink

Google first, ask later.
Jul 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: A | last post by:
Hi, 1) Whats the difference from a virtual function and a pure virtual function? 2) When would you use one over the over? 3) What's the significance of the word virtual? Regards,
9
by: richard.forrest1 | last post by:
I have a problem with an abstract interface class whose implementation classes need to return different iterator types (but with the same value_types etc). Classes A and B both conform to the...
62
by: christopher diggins | last post by:
Since nobody responded to my earlier post , I thought I would try to explain what I am doing a bit differently. When multiply inheriting pure virtual (abstract) base classes, a class obviously...
11
by: Noah Coad [MVP .NET/C#] | last post by:
How do you make a member of a class mandatory to override with a _new_ definition? For example, when inheriting from System.Collections.CollectionBase, you are required to implement certain...
4
by: pocmatos | last post by:
Hi all, I have an abstract class acting as interface to a given class of objects. And mostly everywhere around my program I'm passing things like: vector<int>, list<unsigned long>,...
23
by: Dave Rahardja | last post by:
Since C++ is missing the "interface" concept present in Java, I've been using the following pattern to simulate its behavior: class Interface0 { public: virtual void fn0() = 0; };
14
by: v4vijayakumar | last post by:
Why we need "virtual private member functions"? Why it is not an (compile time) error?
4
by: David Zha0 | last post by:
Hi, "when we call a virtual method, the runtime will check the instance who called the method and then choose the suitable override method, this may causes the performance drop down", is this...
2
by: cmonthenet | last post by:
Hello, I searched for an answer to my question and found similar posts, but none that quite addressed the issue I am trying to resolve. Essentially, it seems like I need something like a virtual...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.