Click here to Skip to main content
15,901,122 members
Home / Discussions / C#
   

C#

 
AnswerRe: How can I pull multiple icons from a single embedded bitmap? Pin
Heath Stewart5-Mar-04 6:14
protectorHeath Stewart5-Mar-04 6:14 
GeneralGraphics, Bitmaps, and a Process that doesn't close Pin
Rendall4-Mar-04 23:35
Rendall4-Mar-04 23:35 
GeneralRe: Graphics, Bitmaps, and a Process that doesn't close Pin
Heath Stewart5-Mar-04 6:07
protectorHeath Stewart5-Mar-04 6:07 
GeneralRe: Graphics, Bitmaps, and a Process that doesn't close Pin
Rendall12-Mar-04 20:01
Rendall12-Mar-04 20:01 
GeneralRe: Graphics, Bitmaps, and a Process that doesn't close Pin
Rendall13-Mar-04 0:11
Rendall13-Mar-04 0:11 
GeneralMarshalling Problem Pin
nvenkat4-Mar-04 23:02
nvenkat4-Mar-04 23:02 
GeneralRe: Marshalling Problem Pin
Roman Rodov4-Mar-04 23:51
Roman Rodov4-Mar-04 23:51 
GeneralRe: Marshalling Problem Pin
nvenkat5-Mar-04 19:19
nvenkat5-Mar-04 19:19 
Generalchecklistbox problem Pin
ASGill4-Mar-04 21:34
ASGill4-Mar-04 21:34 
GeneralRe: checklistbox problem Pin
Mazdak4-Mar-04 21:40
Mazdak4-Mar-04 21:40 
GeneralRe: checklistbox problem Pin
ASGill4-Mar-04 22:09
ASGill4-Mar-04 22:09 
GeneralRe: checklistbox problem Pin
Mazdak4-Mar-04 22:25
Mazdak4-Mar-04 22:25 
GeneralRe: checklistbox problem Pin
ASGill5-Mar-04 0:53
ASGill5-Mar-04 0:53 
GeneralRe: checklistbox problem Pin
MasudM5-Mar-04 1:50
MasudM5-Mar-04 1:50 
GeneralRe: checklistbox problem Pin
Mazdak5-Mar-04 4:51
Mazdak5-Mar-04 4:51 
GeneralRe: checklistbox problem Pin
ASGill5-Mar-04 7:04
ASGill5-Mar-04 7:04 
GeneralYCbCr image construction Pin
yyyychan4-Mar-04 21:12
yyyychan4-Mar-04 21:12 
GeneralI2C communication Pin
yyyychan4-Mar-04 21:05
yyyychan4-Mar-04 21:05 
GeneralRe: I2C communication Pin
Heath Stewart5-Mar-04 6:19
protectorHeath Stewart5-Mar-04 6:19 
GeneralQuestion about Casting and Inheritance Pin
tsunsau7174-Mar-04 19:37
tsunsau7174-Mar-04 19:37 
GeneralRe: Question about Casting and Inheritance Pin
partyganger4-Mar-04 20:50
partyganger4-Mar-04 20:50 
GeneralRe: Question about Casting and Inheritance Pin
tsunsau7174-Mar-04 21:44
tsunsau7174-Mar-04 21:44 
GeneralRe: Question about Casting and Inheritance Pin
partyganger5-Mar-04 10:10
partyganger5-Mar-04 10:10 
GeneralRe: Question about Casting and Inheritance Pin
Roman Rodov4-Mar-04 23:55
Roman Rodov4-Mar-04 23:55 
GeneralRe: Question about Casting and Inheritance Pin
killerslaytanic5-Mar-04 14:23
killerslaytanic5-Mar-04 14:23 
Seems to me you have some misunderstanding about the concepts:

First of all the methods "f" belong to which class(es)?
Second: The typecast (shape)a2 is redundant (don´t remember if it is syntactically ok but if so it has nonsense anyway)a2 is a Square so it IS a Shape anyway

how inheritance and polymorphism works...
I guess you wanted to do something like this:
You have the classes and their respective methods:


class Shape<br />
{<br />
   virtual void f{} to treat the Shape object (Whatever it be) who owns it<br />
}<br />
<br />
class Square : Shape <br />
{<br />
 override void f{}//supposedly to treat the Square object who owns it<br />
<br />
}<br />
<br />
class Circle : Shape <br />
{<br />
 override void f{}//supposedly to treat the Circle object who owns it<br />
}


if you do
Shape a1 = new Shape();
Square a2 = new Square();
Circle a3 = new Circle();

Logically,
a1.f() will call the Shape´s f method; a2.f() the Square´s, etc

BUT ALSO if you do this....( and that´s the nice part)

 Shape a1 ;<br />
 Square a2 = new Square();<br />
 Circle a3 = new Circle();<br />
a1= a2;<br />
a1.f(); //Will call the Square´s f method<br />
a1= a3;<br />
a1.f(); //Will call te Circle´s f method


which is something similar to what you said and is the usual way in which these kind of things are accomplished

This happens because the fmethod is declared virtual in Shape class an is overriden in the child classes otherwise, if they weren´t virtual then the calls of a1.f() always would call the Shape´s f method

Notice this approach is specially useful in this case

Class TestShapes{

void DoSomethingWithShapes(Shape s)
{
s.f();
//it will call the proper f method regarding if s is in fact a Square or a Circle or a general Shape (if this class is conceived to have instances ,thing that generally shouldn´t be taht way)

}
}


Maybe it helps

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.