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

get name of base class from parent

Hi,

If I have a base class, say called "MyBase" and a derived class called
"Myderived" is it possible to get the name of the derived class from the
base class

fo example if I have a method in "MyBase" called "fill" and this method is
not overridden in "Myderived" and I then create and object of my derived and
call the fill method in the base class, the is it possible for the for fill
method of mybase to know it was called from an object of type "Myderived"

what I want to do is set a varable in MyBase.fill to the name of the derived
class (not the name of the instance that called it.)

any help is appreciated.

Thsnk you in advance.

cheers

martin.
Nov 18 '05 #1
3 1568
"martin" <St**************@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Hi,

If I have a base class, say called "MyBase" and a derived class called
"Myderived" is it possible to get the name of the derived class from the
base class

fo example if I have a method in "MyBase" called "fill" and this method is
not overridden in "Myderived" and I then create and object of my derived and call the fill method in the base class, the is it possible for the for fill method of mybase to know it was called from an object of type "Myderived"

what I want to do is set a varable in MyBase.fill to the name of the derived class (not the name of the instance that called it.)


I don't believe you can do this. If "fill" is not overridden in MyDerived,
then it is a MyBase method, and the type of "this" should be MyBase.

On the other hand, I could swear I saw a question like this answered a year
or more ago. I suggest you ask the question again in the
microsoft.public.dotnet.framework newsgroup.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #2
Hi Martin,

You could create a MyBase level property and then set this property in the
contructor of your derived class. I've always built my classes so that the
base classes never need to know about a derived class. If I need different
functionality I'll create a MustOveride function or sub and then put the
different functionality in the class that is deriving from the base. Good
luck! Ken.
"martin" <St**************@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Hi,

If I have a base class, say called "MyBase" and a derived class called
"Myderived" is it possible to get the name of the derived class from the
base class

fo example if I have a method in "MyBase" called "fill" and this method is
not overridden in "Myderived" and I then create and object of my derived and call the fill method in the base class, the is it possible for the for fill method of mybase to know it was called from an object of type "Myderived"

what I want to do is set a varable in MyBase.fill to the name of the derived class (not the name of the instance that called it.)

any help is appreciated.

Thsnk you in advance.

cheers

martin.

Nov 18 '05 #3
Martin,

In your example calling this.GetType().ToString() in "fill" should return
the fully qualified name of Myderived.

Eliyahu

"martin" <St**************@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Hi,

If I have a base class, say called "MyBase" and a derived class called
"Myderived" is it possible to get the name of the derived class from the
base class

fo example if I have a method in "MyBase" called "fill" and this method is
not overridden in "Myderived" and I then create and object of my derived and call the fill method in the base class, the is it possible for the for fill method of mybase to know it was called from an object of type "Myderived"

what I want to do is set a varable in MyBase.fill to the name of the derived class (not the name of the instance that called it.)

any help is appreciated.

Thsnk you in advance.

cheers

martin.

Nov 18 '05 #4

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

Similar topics

9
by: jon wayne | last post by:
OK! I had this nagging doubt Consider (without worrying abt access specifiers) class Kid : public Parent{...}; Parent::someFunc() { Kid k; }
13
by: z. f. | last post by:
Hi, i have a class that is derived from System.Web.UI.Page, and this is the class i use in my application as PageBase. all other page classes are deriverd from my PageBase instead of the...
2
by: Andrew Baker | last post by:
I want to show the parent name of a control in an addin I am writing. However, when I use the following : string parentName = thisControl.Parent.Name // thisControl is of type Control it is...
1
by: smeagol | last post by:
Look this code, well, you know how it works, in "public server (client cl) { cl.Write(); }" "client" is a know class name, but if somebody write a custom start class (like client) and it call to...
4
by: Andrew Backer | last post by:
Hello, I am having a problem creating a class dynamically. The class I have is a base class of another, and the parent class has the constructor (which takes one argument). The base class...
22
by: Boris | last post by:
I'm porting code from Windows to UNIX and ran into a problem with dynamic_cast. Imagine a class hierarchy with three levels: class Level2 derives from Level1 which derives from Base. If you look...
5
by: marfi95 | last post by:
I have a form that has a left and right panel. In the left panel is a treeview. The right panel I want to change dynamically based on the type of node selected. What I'm doing is loading the...
7
by: MarkJ | last post by:
him im kinda new to c-sharp... to reference up the class chain, how do i reference the super class (parent) example class mybase { protected int abc=0 } classs myclass:mybase {
14
by: Jo | last post by:
Hi, Is there a generic way to access the (virtual) functions in the base class of a class? Like in: if (!this->Foo(something)) return(((Base*)this)->Foo(something)); // for a normal member...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.