473,407 Members | 2,306 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,407 software developers and data experts.

Inheritence Question

Hello,

The sample Sub below in Class database accepts a parameter typed as
AdvancedSoftwareDesigns.Table. The problem I am having is if I derive from
AdvancedSoftwareDesigns.Table, i.e. - CLASS myTable INHERITS
AdvancedSoftwareDesigns.Table, so I can add functionality to the class.
When I try to add my derived class using oDatabase.AddTable( oMyClass ) I
get compile error becuase I have Strict ON. If I CTYPE it to
AdvancedSoftwareDesigns.Table I no longer get compile error. The question
I have is if I add any Instance Variable to my derived class will they be
lost when I CTYPE? Also can I cast the object back to be myTable? Or
should I be using a different approach?

Sample Code:
--------------

Public Class Database
Inherits System.Object

Public Sub addTable( byRef Table as AdvancedSoftwareDesigns.Table )
me.tablecollection.Add( Table )
End Sub

End Class
Public Class myTable
Inherits AdvancedSoftwareDesigns.Table

Public someVar as String
Private anotherVar as String

....
End Class
Thanks,
Rob Panosh

Nov 20 '05 #1
2 1096
I've never had a problem with that...

Using CType still retains all the info for the derived class. How does that
work, we don't want to get into that. =)

CJ
"Rob Panosh" <ro************************@asdsoftadfdware.com> wrote in
message news:%2***************@TK2MSFTNGP12.phx.gbl...
Hello,

The sample Sub below in Class database accepts a parameter typed as
AdvancedSoftwareDesigns.Table. The problem I am having is if I derive from AdvancedSoftwareDesigns.Table, i.e. - CLASS myTable INHERITS
AdvancedSoftwareDesigns.Table, so I can add functionality to the class.
When I try to add my derived class using oDatabase.AddTable( oMyClass ) I
get compile error becuase I have Strict ON. If I CTYPE it to
AdvancedSoftwareDesigns.Table I no longer get compile error. The question I have is if I add any Instance Variable to my derived class will they be
lost when I CTYPE? Also can I cast the object back to be myTable? Or
should I be using a different approach?

Sample Code:
--------------

Public Class Database
Inherits System.Object

Public Sub addTable( byRef Table as AdvancedSoftwareDesigns.Table )
me.tablecollection.Add( Table )
End Sub

End Class
Public Class myTable
Inherits AdvancedSoftwareDesigns.Table

Public someVar as String
Private anotherVar as String

....
End Class
Thanks,
Rob Panosh


Nov 20 '05 #2
The sub takes the Table parameter by reference. This means that the
reference could be changed to a different object that is not necessarily of
type myTable (ergo the implicit conversion of the returned reference). There
isn't really any point in having the parameter ByRef so change it to ByVal.

"Rob Panosh" <ro************************@asdsoftadfdware.com> wrote in
message news:%2***************@TK2MSFTNGP12.phx.gbl...
Hello,

The sample Sub below in Class database accepts a parameter typed as
AdvancedSoftwareDesigns.Table. The problem I am having is if I derive from AdvancedSoftwareDesigns.Table, i.e. - CLASS myTable INHERITS
AdvancedSoftwareDesigns.Table, so I can add functionality to the class.
When I try to add my derived class using oDatabase.AddTable( oMyClass ) I
get compile error becuase I have Strict ON. If I CTYPE it to
AdvancedSoftwareDesigns.Table I no longer get compile error. The question I have is if I add any Instance Variable to my derived class will they be
lost when I CTYPE? Also can I cast the object back to be myTable? Or
should I be using a different approach?

Sample Code:
--------------

Public Class Database
Inherits System.Object

Public Sub addTable( byRef Table as AdvancedSoftwareDesigns.Table )
me.tablecollection.Add( Table )
End Sub

End Class
Public Class myTable
Inherits AdvancedSoftwareDesigns.Table

Public someVar as String
Private anotherVar as String

....
End Class
Thanks,
Rob Panosh


Nov 20 '05 #3

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

Similar topics

1
by: John | last post by:
Hi, I am trying to create a class heirarchy similar to the following: // base interface class ICar { public: virtual void start() = 0; }; // add members to that interface, but retain base...
8
by: Digital Puer | last post by:
I made the following table to help me (re)learn inheritence basics. Can someone check if it's correct? This table requires a courier-like font. Java C++ ---- ...
5
by: john bailo | last post by:
For a c# web application, I created a user control that includes a form in control. The idea is, on the main Page, when the user clicks Submit from the master form, that makes the user control...
10
by: Malay Haldar | last post by:
I have a function object, from which I derive another function object in which I overwrite the operator(). But now the operator() in the base class seems inaccessible. For example, the following...
7
by: preetam | last post by:
Hi, This question is more towards design than towards c++ details. By looking at books on design patterns and various google threads on the same topic, I see that composition is favoured to...
7
by: Ron Vecchi | last post by:
Latley I have been messing around with polymorphsim and inheritence and really enjoying the benefits. public myclass() { 'mycode } public myclass(string s) : this() { 'more code
5
by: Neelesh Bodas | last post by:
This might be slightly off-topic. Many books on C++ consider multiple inheritence as an "advanced" concept. Bruce Eckel says in TICPP, volume 2 that "there was (and still is) a lot of...
0
by: tirumalab | last post by:
Hi all, im working on C#, in my current proj we're using one form as the base form and deriving it from all the forms ,its working fine with windows applicatons.But we want to develop the same...
6
by: CapMaster | last post by:
I'm having some trouble using Inheritence classes in c++. I have my base class (Time.h) and my derived class is called (MilTime.h). I started writing my MilTime.cpp for the function definitions. Now,...
4
by: arnaudk | last post by:
I have two unrelated types of data elements (objects) which I want to hold in two related types of containers, one for each element type. But this seems contradictory - for consistency, it seems that...
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: 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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.