473,695 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Casting base class to inherited one

Hi,
We're building a mapping application and inside we're using open
source dll called MapServer. This dll uses object model that has quite
a few classes. In our app we however need to little bit modify come of
the classes so they match our purpose better - mostly add a few
methods etc.
Example: Open source lib has classes Map and Layer defined. The
relationship between them is one to many.
We created our own versions (inherited) of Map called OurMap and our
version of Layer called OurLayer. The only difference between them is
that they have some extra methods (because we need them to do little
bit extra).
Is there any way how can I convert the base class (either Map or
Layer) to our inherited one (OurMap or OurLayer)?
I know that implicit or explicit conversion operators don't work
between inherited and base class but I was just wondering if there is
another way how to do this or if there's something wrong with our
object design?
Thanks for any help

Jul 31 '07 #1
19 2229
On Jul 30, 8:47 pm, jan.lou...@gmai l.com wrote:
Hi,
We're building a mapping application and inside we're using open
source dll called MapServer. This dll uses object model that has quite
a few classes. In our app we however need to little bit modify come of
the classes so they match our purpose better - mostly add a few
methods etc.
Example: Open source lib has classes Map and Layer defined. The
relationship between them is one to many.
We created our own versions (inherited) of Map called OurMap and our
version of Layer called OurLayer. The only difference between them is
that they have some extra methods (because we need them to do little
bit extra).
Is there any way how can I convert the base class (either Map or
Layer) to our inherited one (OurMap or OurLayer)?
I know that implicit or explicit conversion operators don't work
between inherited and base class
Who told you that? It's certainly not true. C# allows you to write
your own conversion operator, either implicit or explicit, that copies
the members from your base class object into a new, derived class
object, and return the derived object.

The only hitch, of course, is that you end up with a copy, but there's
no way around that.

Jul 31 '07 #2
On Jul 31, 11:52 am, Bruce Wood <brucew...@cana da.comwrote:
On Jul 30, 8:47 pm, jan.lou...@gmai l.com wrote:
Hi,
We're building a mapping application and inside we're using open
source dll called MapServer. This dll uses object model that has quite
a few classes. In our app we however need to little bit modify come of
the classes so they match our purpose better - mostly add a few
methods etc.
Example: Open source lib has classes Map and Layer defined. The
relationship between them is one to many.
We created our own versions (inherited) of Map called OurMap and our
version of Layer called OurLayer. The only difference between them is
that they have some extra methods (because we need them to do little
bit extra).
Is there any way how can I convert the base class (either Map or
Layer) to our inherited one (OurMap or OurLayer)?
I know that implicit or explicit conversion operators don't work
between inherited and base class

Who told you that? It's certainly not true. C# allows you to write
your own conversion operator, either implicit or explicit, that copies
the members from your base class object into a new, derived class
object, and return the derived object.

The only hitch, of course, is that you end up with a copy, but there's
no way around that.
When I try that the compiler complains:
C:\MapServer\In traMaps60\Spati alEngineWS\Laye rs
\IntraMapsLayer .cs(208): 'DMS.IntraMaps. IntraMapsLayer. implicit
operator DMS.IntraMaps.I ntraMapsLayer(l ayerObj)': user-defined
conversion to/from base class
I googled it and I found some articles that you cannot implicitly
convert from base class to it's child.
Am I doing something wrong?

Jul 31 '07 #3
On Jul 30, 9:00 pm, jan.lou...@gmai l.com wrote:
On Jul 31, 11:52 am, Bruce Wood <brucew...@cana da.comwrote:


On Jul 30, 8:47 pm, jan.lou...@gmai l.com wrote:
Hi,
We're building a mapping application and inside we're using open
source dll called MapServer. This dll uses object model that has quite
a few classes. In our app we however need to little bit modify come of
the classes so they match our purpose better - mostly add a few
methods etc.
Example: Open source lib has classes Map and Layer defined. The
relationship between them is one to many.
We created our own versions (inherited) of Map called OurMap and our
version of Layer called OurLayer. The only difference between them is
that they have some extra methods (because we need them to do little
bit extra).
Is there any way how can I convert the base class (either Map or
Layer) to our inherited one (OurMap or OurLayer)?
I know that implicit or explicit conversion operators don't work
between inherited and base class
Who told you that? It's certainly not true. C# allows you to write
your own conversion operator, either implicit or explicit, that copies
the members from your base class object into a new, derived class
object, and return the derived object.
The only hitch, of course, is that you end up with a copy, but there's
no way around that.

When I try that the compiler complains:
C:\MapServer\In traMaps60\Spati alEngineWS\Laye rs
\IntraMapsLayer .cs(208): 'DMS.IntraMaps. IntraMapsLayer. implicit
operator DMS.IntraMaps.I ntraMapsLayer(l ayerObj)': user-defined
conversion to/from base class
I googled it and I found some articles that you cannot implicitly
convert from base class to it's child.
Am I doing something wrong?
Could you post the code you wrote? Both your definition of the
implicit conversion operator and your use of it?

Jul 31 '07 #4
On Jul 30, 9:43 pm, Bruce Wood <brucew...@cana da.comwrote:
On Jul 30, 9:00 pm, jan.lou...@gmai l.com wrote:


On Jul 31, 11:52 am, Bruce Wood <brucew...@cana da.comwrote:
On Jul 30, 8:47 pm, jan.lou...@gmai l.com wrote:
Hi,
We're building a mapping application and inside we're using open
source dll called MapServer. This dll uses object model that has quite
a few classes. In our app we however need to little bit modify come of
the classes so they match our purpose better - mostly add a few
methods etc.
Example: Open source lib has classes Map and Layer defined. The
relationship between them is one to many.
We created our own versions (inherited) of Map called OurMap and our
version of Layer called OurLayer. The only difference between them is
that they have some extra methods (because we need them to do little
bit extra).
Is there any way how can I convert the base class (either Map or
Layer) to our inherited one (OurMap or OurLayer)?
I know that implicit or explicit conversion operators don't work
between inherited and base class
Who told you that? It's certainly not true. C# allows you to write
your own conversion operator, either implicit or explicit, that copies
the members from your base class object into a new, derived class
object, and return the derived object.
The only hitch, of course, is that you end up with a copy, but there's
no way around that.
When I try that the compiler complains:
C:\MapServer\In traMaps60\Spati alEngineWS\Laye rs
\IntraMapsLayer .cs(208): 'DMS.IntraMaps. IntraMapsLayer. implicit
operator DMS.IntraMaps.I ntraMapsLayer(l ayerObj)': user-defined
conversion to/from base class
I googled it and I found some articles that you cannot implicitly
convert from base class to it's child.
Am I doing something wrong?

Could you post the code you wrote? Both your definition of the
implicit conversion operator and your use of it?
Forget it. I just read the C# spec on line, here:

http://msdn2.microsoft.com/en-us/lib...64(VS.71).aspx

It says quite clearly that I'm wrong: you cannot provide implicit or
explicit conversions either up or down the class hierarchy.

Which means that the only option left open to you is a copy
constructor: your derived class must have a constructor that accepts a
member of your base class, like this:

public class Derived : Base
{
public Derived(Base baseObject)
{
...
}
}

or, you could make it a static method in your derived class:

public static Derived DerivedFromBase (Base baseObject) { ... }

Bummer about the conversions, though. I guess it causes some sort of
problem within the CLR....

Jul 31 '07 #5
On Jul 31, 12:43 pm, Bruce Wood <brucew...@cana da.comwrote:
On Jul 30, 9:00 pm, jan.lou...@gmai l.com wrote:
On Jul 31, 11:52 am, Bruce Wood <brucew...@cana da.comwrote:
On Jul 30, 8:47 pm, jan.lou...@gmai l.com wrote:
Hi,
We're building a mapping application and inside we're using open
source dll called MapServer. This dll uses object model that has quite
a few classes. In our app we however need to little bit modify come of
the classes so they match our purpose better - mostly add a few
methods etc.
Example: Open source lib has classes Map and Layer defined. The
relationship between them is one to many.
We created our own versions (inherited) of Map called OurMap and our
version of Layer called OurLayer. The only difference between them is
that they have some extra methods (because we need them to do little
bit extra).
Is there any way how can I convert the base class (either Map or
Layer) to our inherited one (OurMap or OurLayer)?
I know that implicit or explicit conversion operators don't work
between inherited and base class
Who told you that? It's certainly not true. C# allows you to write
your own conversion operator, either implicit or explicit, that copies
the members from your base class object into a new, derived class
object, and return the derived object.
The only hitch, of course, is that you end up with a copy, but there's
no way around that.
When I try that the compiler complains:
C:\MapServer\In traMaps60\Spati alEngineWS\Laye rs
\IntraMapsLayer .cs(208): 'DMS.IntraMaps. IntraMapsLayer. implicit
operator DMS.IntraMaps.I ntraMapsLayer(l ayerObj)': user-defined
conversion to/from base class
I googled it and I found some articles that you cannot implicitly
convert from base class to it's child.
Am I doing something wrong?

Could you post the code you wrote? Both your definition of the
implicit conversion operator and your use of it?
This is my inherited class:

public class IntraMapsLayer : layerObj
{
public IntraMapsLayer( superMapObj map) : base (map)
{
this.currentSup erMapObj = map;
}

public static implicit operator IntraMapsLayer( layerObj layer)
{
IntraMapsLayer newLayer = new IntraMapsLayer( this.map);
newLayer.bandsi tem = layer.bandsitem ;
newLayer.classi tem = layer.classitem ;
newLayer.connec tion = layer.connectio n;
newLayer.connec tiontype = layer.connectio ntype;
newLayer.data = layer.data;
newLayer.debug = layer.debug;
newLayer.dump = layer.dump;
//newLayer.extent = layer.extent;
newLayer.filter item = layer.filterite m;
newLayer.footer = layer.footer;
newLayer.group = layer.group;
newLayer.header = layer.header;
//newLayer.index = layer.index;
newLayer.labela ngleitem = layer.labelangl eitem;
newLayer.labelc ache = layer.labelcach e;
newLayer.labeli tem = layer.labelitem ;
newLayer.labelm axscale = layer.labelmaxs cale;
newLayer.labelm inscale = layer.labelmins cale;
newLayer.labelr equires = layer.labelrequ ires;
newLayer.labels izeitem = layer.labelsize item;
//newLayer.map = layer.map;
newLayer.maxfea tures = layer.maxfeatur es;
newLayer.maxsca le = layer.maxscale;
//newLayer.metada ta = layer.metadata;
newLayer.minsca le = layer.minscale;
newLayer.name = layer.name;
//newLayer.numcla sses = layer.numclasse s;
//newLayer.numite ms = layer.numitems;
//newLayer.numjoi ns = layer.numjoins;
//newLayer.numpro cessing = layer.numproces sing;
newLayer.offsit e = layer.offsite;
newLayer.plugin _library = layer.plugin_li brary;
newLayer.plugin _library_origin al = layer.plugin_li brary_original;
newLayer.postla belcache = layer.postlabel cache;
newLayer.requir es = layer.requires;
newLayer.sizeun its = layer.sizeunits ;
newLayer.status = layer.status;
newLayer.stylei tem = layer.styleitem ;
newLayer.symbol scale = layer.symbolsca le;
newLayer.templa te = layer.template;
newLayer.tilein dex = layer.tileindex ;
newLayer.tileit em = layer.tileitem;
newLayer.tolera nce = layer.tolerance ;
newLayer.tolera nceunits = layer.tolerance units;
newLayer.transf orm = layer.transform ;
newLayer.transp arency = layer.transpare ncy;
newLayer.type = layer.type;
newLayer.units = layer.units;
return newLayer;
}
this implicit operator does not even compile. I haven't mentioned it
yet but we're bound to .NET 1.1 unfortunatelly

Jul 31 '07 #6
On Jul 31, 12:51 pm, Bruce Wood <brucew...@cana da.comwrote:
On Jul 30, 9:43 pm, Bruce Wood <brucew...@cana da.comwrote:
On Jul 30, 9:00 pm, jan.lou...@gmai l.com wrote:
On Jul 31, 11:52 am, Bruce Wood <brucew...@cana da.comwrote:
On Jul 30, 8:47 pm, jan.lou...@gmai l.com wrote:
Hi,
We're building a mapping application and inside we're using open
source dll called MapServer. This dll uses object model that has quite
a few classes. In our app we however need to little bit modify come of
the classes so they match our purpose better - mostly add a few
methods etc.
Example: Open source lib has classes Map and Layer defined. The
relationship between them is one to many.
We created our own versions (inherited) of Map called OurMap and our
version of Layer called OurLayer. The only difference between them is
that they have some extra methods (because we need them to do little
bit extra).
Is there any way how can I convert the base class (either Map or
Layer) to our inherited one (OurMap or OurLayer)?
I know that implicit or explicit conversion operators don't work
between inherited and base class
Who told you that? It's certainly not true. C# allows you to write
your own conversion operator, either implicit or explicit, that copies
the members from your base class object into a new, derived class
object, and return the derived object.
The only hitch, of course, is that you end up with a copy, but there's
no way around that.
When I try that the compiler complains:
C:\MapServer\In traMaps60\Spati alEngineWS\Laye rs
\IntraMapsLayer .cs(208): 'DMS.IntraMaps. IntraMapsLayer. implicit
operator DMS.IntraMaps.I ntraMapsLayer(l ayerObj)': user-defined
conversion to/from base class
I googled it and I found some articles that you cannot implicitly
convert from base class to it's child.
Am I doing something wrong?
Could you post the code you wrote? Both your definition of the
implicit conversion operator and your use of it?

Forget it. I just read the C# spec on line, here:

http://msdn2.microsoft.com/en-us/lib...64(VS.71).aspx

It says quite clearly that I'm wrong: you cannot provide implicit or
explicit conversions either up or down the class hierarchy.

Which means that the only option left open to you is a copy
constructor: your derived class must have a constructor that accepts a
member of your base class, like this:

public class Derived : Base
{
public Derived(Base baseObject)
{
...
}

}

or, you could make it a static method in your derived class:

public static Derived DerivedFromBase (Base baseObject) { ... }

Bummer about the conversions, though. I guess it causes some sort of
problem within the CLR....
I didn't get what was the copy constructor supposed to do - can u
explain it to me?

Jul 31 '07 #7
Who told you that? It's certainly not true. C# allows you to write
your own conversion operator, either implicit or explicit, that copies
the members from your base class object into a new, derived class
object, and return the derived object.
So does VB .NET 2005.
Jul 31 '07 #8
ja********@gmai l.com wrote:
On Jul 31, 12:43 pm, Bruce Wood <brucew...@cana da.comwrote:
>On Jul 30, 9:00 pm, jan.lou...@gmai l.com wrote:
>>On Jul 31, 11:52 am, Bruce Wood <brucew...@cana da.comwrote:
On Jul 30, 8:47 pm, jan.lou...@gmai l.com wrote:
Hi,
We're building a mapping application and inside we're using open
source dll called MapServer. This dll uses object model that has quite
a few classes. In our app we however need to little bit modify come of
the classes so they match our purpose better - mostly add a few
methods etc.
Example: Open source lib has classes Map and Layer defined. The
relationshi p between them is one to many.
We created our own versions (inherited) of Map called OurMap and our
version of Layer called OurLayer. The only difference between them is
that they have some extra methods (because we need them to do little
bit extra).
Is there any way how can I convert the base class (either Map or
Layer) to our inherited one (OurMap or OurLayer)?
I know that implicit or explicit conversion operators don't work
between inherited and base class
Who told you that? It's certainly not true. C# allows you to write
your own conversion operator, either implicit or explicit, that copies
the members from your base class object into a new, derived class
object, and return the derived object.
The only hitch, of course, is that you end up with a copy, but there's
no way around that.
When I try that the compiler complains:
C:\MapServer\ IntraMaps60\Spa tialEngineWS\La yers
\IntraMapsLay er.cs(208): 'DMS.IntraMaps. IntraMapsLayer. implicit
operator DMS.IntraMaps.I ntraMapsLayer(l ayerObj)': user-defined
conversion to/from base class
I googled it and I found some articles that you cannot implicitly
convert from base class to it's child.
Am I doing something wrong?
Could you post the code you wrote? Both your definition of the
implicit conversion operator and your use of it?

This is my inherited class:

public class IntraMapsLayer : layerObj
{
public IntraMapsLayer( superMapObj map) : base (map)
{
this.currentSup erMapObj = map;
}

public static implicit operator IntraMapsLayer( layerObj layer)
{
IntraMapsLayer newLayer = new IntraMapsLayer( this.map);
newLayer.bandsi tem = layer.bandsitem ;
newLayer.classi tem = layer.classitem ;
newLayer.connec tion = layer.connectio n;
newLayer.connec tiontype = layer.connectio ntype;
newLayer.data = layer.data;
newLayer.debug = layer.debug;
newLayer.dump = layer.dump;
//newLayer.extent = layer.extent;
newLayer.filter item = layer.filterite m;
newLayer.footer = layer.footer;
newLayer.group = layer.group;
newLayer.header = layer.header;
//newLayer.index = layer.index;
newLayer.labela ngleitem = layer.labelangl eitem;
newLayer.labelc ache = layer.labelcach e;
newLayer.labeli tem = layer.labelitem ;
newLayer.labelm axscale = layer.labelmaxs cale;
newLayer.labelm inscale = layer.labelmins cale;
newLayer.labelr equires = layer.labelrequ ires;
newLayer.labels izeitem = layer.labelsize item;
//newLayer.map = layer.map;
newLayer.maxfea tures = layer.maxfeatur es;
newLayer.maxsca le = layer.maxscale;
//newLayer.metada ta = layer.metadata;
newLayer.minsca le = layer.minscale;
newLayer.name = layer.name;
//newLayer.numcla sses = layer.numclasse s;
//newLayer.numite ms = layer.numitems;
//newLayer.numjoi ns = layer.numjoins;
//newLayer.numpro cessing = layer.numproces sing;
newLayer.offsit e = layer.offsite;
newLayer.plugin _library = layer.plugin_li brary;
newLayer.plugin _library_origin al = layer.plugin_li brary_original;
newLayer.postla belcache = layer.postlabel cache;
newLayer.requir es = layer.requires;
newLayer.sizeun its = layer.sizeunits ;
newLayer.status = layer.status;
newLayer.stylei tem = layer.styleitem ;
newLayer.symbol scale = layer.symbolsca le;
newLayer.templa te = layer.template;
newLayer.tilein dex = layer.tileindex ;
newLayer.tileit em = layer.tileitem;
newLayer.tolera nce = layer.tolerance ;
newLayer.tolera nceunits = layer.tolerance units;
newLayer.transf orm = layer.transform ;
newLayer.transp arency = layer.transpare ncy;
newLayer.type = layer.type;
newLayer.units = layer.units;
return newLayer;
}
this implicit operator does not even compile. I haven't mentioned it
yet but we're bound to .NET 1.1 unfortunatelly
Have you tried this:

return (IntraMapsLayer )newLayer;

And why not go OO? There really is no need for the copy constructor and
the implicit conversion operator you are attempting to write. It just
makes for extra code that you'll then have to debug and maintain. And I
don't understand the purpose of the currentSuperMap Obj since that is you
(IntraMapsLayer )!

public class IntraMapsLayer : layerObj // why is this call "Obj"
// do you really have a class
// called layerObj?
int _i1, _i2;
{
public IntraMapsLayer( int i1, int i2) : base (map)
{
_i1 = i1;
_i2 = i2;
}
}

IntraMapsLayer layer1 = new layerObj(1, 2);

The constructor then only needs to deals with any fields in the
IntraMapsLayer that are not in the base class. You can then up-cast if
you want:

layerObj layer2 = (IntraMapsLayer )layer1;

so that you can get at the fields specific to the layerObj class.

HTH

--
-glenn-
Jul 31 '07 #9
On Jul 31, 9:13 pm, "G.Doten" <gdo...@gmail.c omwrote:
jan.lou...@gmai l.com wrote:
On Jul 31, 12:43 pm, Bruce Wood <brucew...@cana da.comwrote:
On Jul 30, 9:00 pm, jan.lou...@gmai l.com wrote:
>On Jul 31, 11:52 am, Bruce Wood <brucew...@cana da.comwrote:
On Jul 30, 8:47 pm, jan.lou...@gmai l.com wrote:
Hi,
We're building a mapping application and inside we're using open
source dll called MapServer. This dll uses object model that has quite
a few classes. In our app we however need to little bit modify come of
the classes so they match our purpose better - mostly add a few
methods etc.
Example: Open source lib has classes Map and Layer defined. The
relationsh ip between them is one to many.
We created our own versions (inherited) of Map called OurMap and our
version of Layer called OurLayer. The only difference between them is
that they have some extra methods (because we need them to do little
bit extra).
Is there any way how can I convert the base class (either Map or
Layer) to our inherited one (OurMap or OurLayer)?
I know that implicit or explicit conversion operators don't work
between inherited and base class
Who told you that? It's certainly not true. C# allows you to write
your own conversion operator, either implicit or explicit, that copies
the members from your base class object into a new, derived class
object, and return the derived object.
The only hitch, of course, is that you end up with a copy, but there's
no way around that.
When I try that the compiler complains:
C:\MapServer\I ntraMaps60\Spat ialEngineWS\Lay ers
\IntraMapsLaye r.cs(208): 'DMS.IntraMaps. IntraMapsLayer. implicit
operator DMS.IntraMaps.I ntraMapsLayer(l ayerObj)': user-defined
conversion to/from base class
I googled it and I found some articles that you cannot implicitly
convert from base class to it's child.
Am I doing something wrong?
Could you post the code you wrote? Both your definition of the
implicit conversion operator and your use of it?
This is my inherited class:
public class IntraMapsLayer : layerObj
{
public IntraMapsLayer( superMapObj map) : base (map)
{
this.currentSup erMapObj = map;
}
public static implicit operator IntraMapsLayer( layerObj layer)
{
IntraMapsLayer newLayer = new IntraMapsLayer( this.map);
newLayer.bandsi tem = layer.bandsitem ;
newLayer.classi tem = layer.classitem ;
newLayer.connec tion = layer.connectio n;
newLayer.connec tiontype = layer.connectio ntype;
newLayer.data = layer.data;
newLayer.debug = layer.debug;
newLayer.dump = layer.dump;
//newLayer.extent = layer.extent;
newLayer.filter item = layer.filterite m;
newLayer.footer = layer.footer;
newLayer.group = layer.group;
newLayer.header = layer.header;
//newLayer.index = layer.index;
newLayer.labela ngleitem = layer.labelangl eitem;
newLayer.labelc ache = layer.labelcach e;
newLayer.labeli tem = layer.labelitem ;
newLayer.labelm axscale = layer.labelmaxs cale;
newLayer.labelm inscale = layer.labelmins cale;
newLayer.labelr equires = layer.labelrequ ires;
newLayer.labels izeitem = layer.labelsize item;
//newLayer.map = layer.map;
newLayer.maxfea tures = layer.maxfeatur es;
newLayer.maxsca le = layer.maxscale;
//newLayer.metada ta = layer.metadata;
newLayer.minsca le = layer.minscale;
newLayer.name = layer.name;
//newLayer.numcla sses = layer.numclasse s;
//newLayer.numite ms = layer.numitems;
//newLayer.numjoi ns = layer.numjoins;
//newLayer.numpro cessing = layer.numproces sing;
newLayer.offsit e = layer.offsite;
newLayer.plugin _library = layer.plugin_li brary;
newLayer.plugin _library_origin al = layer.plugin_li brary_original;
newLayer.postla belcache = layer.postlabel cache;
newLayer.requir es = layer.requires;
newLayer.sizeun its = layer.sizeunits ;
newLayer.status = layer.status;
newLayer.stylei tem = layer.styleitem ;
newLayer.symbol scale = layer.symbolsca le;
newLayer.templa te = layer.template;
newLayer.tilein dex = layer.tileindex ;
newLayer.tileit em = layer.tileitem;
newLayer.tolera nce = layer.tolerance ;
newLayer.tolera nceunits = layer.tolerance units;
newLayer.transf orm = layer.transform ;
newLayer.transp arency = layer.transpare ncy;
newLayer.type = layer.type;
newLayer.units = layer.units;
return newLayer;
}
this implicit operator does not even compile. I haven't mentioned it
yet but we're bound to .NET 1.1 unfortunatelly

Have you tried this:

return (IntraMapsLayer )newLayer;

And why not go OO? There really is no need for the copy constructor and
the implicit conversion operator you are attempting to write. It just
makes for extra code that you'll then have to debug and maintain. And I
don't understand the purpose of the currentSuperMap Obj since that is you
(IntraMapsLayer )!

public class IntraMapsLayer : layerObj // why is this call "Obj"
// do you really have a class
// called layerObj?
int _i1, _i2;
{
public IntraMapsLayer( int i1, int i2) : base (map)
{
_i1 = i1;
_i2 = i2;
}

}

IntraMapsLayer layer1 = new layerObj(1, 2);

The constructor then only needs to deals with any fields in the
IntraMapsLayer that are not in the base class. You can then up-cast if
you want:

layerObj layer2 = (IntraMapsLayer )layer1;

so that you can get at the fields specific to the layerObj class.

HTH

--
-glenn-
as I described in my first email - we actually have a class called
layerObj. It comes from open source dll so we cannot change it. We
need to add some extra functionality to it - we did that by creating
derived class called IntraMapsLayer thus public class IntraMapsLayer :
layerObj

Whenever you do this - your implicit conversion operator:
(IntraMapsLayer ) layer1 would not work!! You can try it but that is
what this topic is about. You cannot do that. At firts - you have to
write your own implicit conversion operator to do this. And second you
cannot write this conversion operator because you're trying to convert
base class to it's child. .NET doesn't allow that.

Aug 1 '07 #10

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

Similar topics

7
2591
by: James Brown | last post by:
I have two classes, a base class, and a class base { public: base(); virtual void foo() = 0; }; class derived : public base
2
2560
by: Zac | last post by:
Alright anyone who has 2c throw it in... I am working through a custom xml serializer and have come upon a conundrum, given our class design. The interface implemented on the base class (base for all business entities) dictates that the implementing class expose a Dirty property (for state). The base class (that actually manages state, once for all inheritors)
1
281
by: Remco | last post by:
Hi, Let me try to simply explain my questions. I've created a portal site with different types of users, e.g. Portal Administrators and Normal Users. One base class SessionUser (has a enum field UserType) and for each type of user a inherited class like SessionMasterUser and SessionNormalUser.
5
3157
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 CommonPageBase - Contains myPage which inherits PageBase Each of these classes overrides OnInit and ties an event handler
8
2125
by: Michael | last post by:
Hi, I think my problem deals with class casting and inheritance. I want to deal with various Audio Formats, reading into memory for modification, working with it (done by different classes), and writing the result to disk afterwards. Therefore I have created some classes, e.g. WaveFileIO and AiffFileIO and MP3FileIO and AuFileIO for the In/Out operations.
1
7955
by: conchur | last post by:
Is there an elegant way to have a class utilise an inherited method to return a Typed Collection of itself? Example: class MyList<T> : List<T> where T : MyRoot { Add... Remove... }
10
1741
by: Brett Romero | last post by:
Say I have a class inheriting some base class: BaseClass { void Foo() { Update(); } }
9
2455
by: Jess | last post by:
Hello, It seems both static_cast and dynamic_cast can cast a base class pointer/reference to a derived class pointer/reference. If so, is there any difference between them? In addition, if I have a derived class object and then upcast it to its base class, which cast operator should I use? Is it static_cast, or, can I simply cast it implicitly without any operator? Does this upcasting remove the derived class portion of the object?...
19
3359
by: jan.loucka | last post by:
Hi, We're building a mapping application and inside we're using open source dll called MapServer. This dll uses object model that has quite a few classes. In our app we however need to little bit modify come of the classes so they match our purpose better - mostly add a few methods etc. Example: Open source lib has classes Map and Layer defined. The relationship between them is one to many. We created our own versions (inherited) of Map...
0
8631
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8984
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8825
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7661
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5839
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4340
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2272
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.