473,322 Members | 1,409 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,322 software developers and data experts.

How to tell if a class inherits another class?

Don
1. Say I have three classes: A, B and C.

2. Class A can only be inherited, and B inherits it. C does not inherit
anything.

3. I have a function that can have an object passed to it. Either B or C
can be passed to it.

4. In this function, I need to determine whether the object passed to it
inherits A or not.
In pseudo-code:

Function MyFunction(object)

If object.Inherits(A) Then
Return "Inherits A"
Else
Return "Does not inherit A"
End If

End Function
MyFunction(B) --> "Inherits A"
MyFunction(C) --> "Does not inherits A"
Is there any way to do this?

- Don
Nov 21 '05 #1
2 1356
Don
Try the IsSubclassOf method:
Function MyFunction(object)

If object.GetType.IsSubclassOf (A) Then
Return "Inherits A"
Else
Return "Does not inherit A"
End If

End Function


"Don" <un*****@oblivion.com> wrote in message
news:q2Add.780449$M95.726062@pd7tw1no...
1. Say I have three classes: A, B and C.

2. Class A can only be inherited, and B inherits it. C does not inherit
anything.

3. I have a function that can have an object passed to it. Either B or C
can be passed to it.

4. In this function, I need to determine whether the object passed to it
inherits A or not.
In pseudo-code:

Function MyFunction(object)

If object.Inherits(A) Then
Return "Inherits A"
Else
Return "Does not inherit A"
End If

End Function
MyFunction(B) --> "Inherits A"
MyFunction(C) --> "Does not inherits A"
Is there any way to do this?

- Don

Nov 21 '05 #2
Don
Thanks! That works!
"Don" <un*****@oblivion.com> wrote in message
news:o8Add.780496$M95.307704@pd7tw1no...
Try the IsSubclassOf method:
Function MyFunction(object)

If object.GetType.IsSubclassOf (A) Then
Return "Inherits A"
Else
Return "Does not inherit A"
End If

End Function


"Don" <un*****@oblivion.com> wrote in message
news:q2Add.780449$M95.726062@pd7tw1no...
1. Say I have three classes: A, B and C.

2. Class A can only be inherited, and B inherits it. C does not inherit
anything.

3. I have a function that can have an object passed to it. Either B or C can be passed to it.

4. In this function, I need to determine whether the object passed to it
inherits A or not.
In pseudo-code:

Function MyFunction(object)

If object.Inherits(A) Then
Return "Inherits A"
Else
Return "Does not inherit A"
End If

End Function
MyFunction(B) --> "Inherits A"
MyFunction(C) --> "Does not inherits A"
Is there any way to do this?

- Don


Nov 21 '05 #3

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

Similar topics

18
by: jrhoads23 | last post by:
Hello, I am trying to find a way to tell if an .NET windows forms Button (System.Windows.Forms.Button) is "depressed" (pushed down). For my application, I can not use a check box control set to...
6
by: mister.mwa | last post by:
Hello, I have the following problem: I have a class Foo, and a class Bar. I want Foo to inherit from Bar, but i want to put them in separate files Foo.vb and Bar.vb. Then i will use the Foo...
5
by: Andy | last post by:
Hi all, I have a site with the following architecture: Common.Web.dll - Contains a CommonPageBase class which inherits System.Web.UI.Page myadd.dll - Contains PageBase which inherits...
0
by: Mike | last post by:
Hi All, I am using a COM object and so I have to use a form for it to work. The problem is I need to run it as a service as well. When I run it in a test scenario everything works fine and...
6
by: Philip Warner | last post by:
I have a set of classes: C (base) C1 (inherits C) C2 (inherits C) ... Cn (inherits C) (the C1..Cn also have subclasses, but thats not really relevant to the question)
9
by: David A. Osborn | last post by:
I have a set of classes that each have an enumeration in them, and based on dynamic input I need to access a different enumeration. For example Three classes Class_A, Class_B, and Class_C that...
1
by: miben | last post by:
I want to create a new inherited class givin its base. For example: class Base { public: void operator =(const Base &base) { // copy base items } }; class Inherits: public Base {
5
by: D Witherspoon | last post by:
What is happening is that I have a class (ClassA) that inherits a class (ClassB) which inherits System.Net.Mail.MailMessage Project 1 references Project 2, Project 2 references Project 3. ...
1
by: davebaranas | last post by:
I am able to serialize this but I get a null exception when I try to deserialize it back Even if I don't make any child classes it throws "Object reference not set to an instance of an object."...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.