abstract class constructor?
-
This is what I want to do:
abstract class Item { abstract Item(int x, int y) { x = X; y = Y; } } class Transistor : Item { Transistor(int X, int Y) { x = X; y = Y; //some other funcs } }
But it wont work. How could I solve it? I got an idea on how to do it... Like this:abstract class Item { abstract Item(int x, int y) { x = X; y = Y; this.init(); } } class Transistor : Item { init(int X, int Y) { //some other funcs } }
But isn't there a better way? Niklas Ulvinge aka IDK -
This is what I want to do:
abstract class Item { abstract Item(int x, int y) { x = X; y = Y; } } class Transistor : Item { Transistor(int X, int Y) { x = X; y = Y; //some other funcs } }
But it wont work. How could I solve it? I got an idea on how to do it... Like this:abstract class Item { abstract Item(int x, int y) { x = X; y = Y; this.init(); } } class Transistor : Item { init(int X, int Y) { //some other funcs } }
But isn't there a better way? Niklas Ulvinge aka IDKAre you trying something like this? abstract class Item {
public Item(int x, int y) {
//...
}
}class Transistor : Item {
public Transistor(int x, int y) : base(x, y) {
//..
}
} -
This is what I want to do:
abstract class Item { abstract Item(int x, int y) { x = X; y = Y; } } class Transistor : Item { Transistor(int X, int Y) { x = X; y = Y; //some other funcs } }
But it wont work. How could I solve it? I got an idea on how to do it... Like this:abstract class Item { abstract Item(int x, int y) { x = X; y = Y; this.init(); } } class Transistor : Item { init(int X, int Y) { //some other funcs } }
But isn't there a better way? Niklas Ulvinge aka IDK -
The incomplete code that you show doesn't tell me what it is that you want to do. Can you explain what it is that you are trying to accomplish? --- b { font-weight: normal; }
I thought I needed to create an instance of item, wich I didn't have to and couldn't do... I simply removed the construcor and it worked fine. Thanks for your replies. I'm tired and can't think really well now, but now is the only time I can program, (at other times it's only homework, school and more homework). Niklas Ulvinge aka IDK
-
This is what I want to do:
abstract class Item { abstract Item(int x, int y) { x = X; y = Y; } } class Transistor : Item { Transistor(int X, int Y) { x = X; y = Y; //some other funcs } }
But it wont work. How could I solve it? I got an idea on how to do it... Like this:abstract class Item { abstract Item(int x, int y) { x = X; y = Y; this.init(); } } class Transistor : Item { init(int X, int Y) { //some other funcs } }
But isn't there a better way? Niklas Ulvinge aka IDKbest practices of Microsoft recommends the following: abstract class Item { protected Item(int x, int y) { ... } } class Transistor : Item { public Transistor(int x, int y) : base(x,y) { } } Eduardo Diaz site | english blog | spanish blog
-
best practices of Microsoft recommends the following: abstract class Item { protected Item(int x, int y) { ... } } class Transistor : Item { public Transistor(int x, int y) : base(x,y) { } } Eduardo Diaz site | english blog | spanish blog
That was what I'm looking for, thanks Niklas Ulvinge aka IDK