Hi, but this isn't c++......However:
abstract baseClass {
List <baseClass> list = new List<BaseClass>();
List<Two> list_two=new List<Two>();
virtual add(BaseClass class) {
list.Add(class);
if (class.Type is "Two" ) list_two.Add((Two) class);
/* is correct put this above here? Maybe Was better put it in [1] ? */
class.value = 10; //does it make sense???
}
}
class One : baseClass {
One (){}
override void add(BaseClass class) {
// ----------- [1]
// do something
base.add(class);
}
}
class Two : baseClass{
Two() {}
//constructor and the rest
int value;
}
main {
Two two;
One one;
one.add(new two() ); // here the object two is "converted" to its base class; the base
//class hasn't value field: is this "convertion" and the "cast" like you have advice,
//could have any problem ???
}
abstract baseClass {
List <baseClass> list = new List<BaseClass>();
List<Two> list_two=new List<Two>();
virtual add(BaseClass class) {
list.Add(class);
if (class.Type is "Two" ) list_two.Add((Two) class);
/* is correct put this above here? Maybe Was better put it in [1] ? */
class.value = 10; //does it make sense???
}
}
class One : baseClass {
One (){}
override void add(BaseClass class) {
// ----------- [1]
// do something
base.add(class);
}
}
class Two : baseClass{
Two() {}
//constructor and the rest
int value;
}
main {
Two two;
One one;
one.add(new two() ); // here the object two is "converted" to its base class; the base
//class hasn't value field: is this "convertion" and the "cast" like you have advice,
//could have any problem ???
}
To copy to clipboard, switch view to plain text mode
Bookmarks