Virtual

1 / 14

# Virtual - PowerPoint PPT Presentation

Virtual. CNS 4490. Example. class One { int a; One(int a1){a = a1;} int geta(){return a;} virtual int times(){return 2*a;} }; class Two : One { int b; Two(int a1,int b1):One(a1){b=b1;} override int times(){return b*a;} }; class Three{ void main( ) {

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about 'Virtual' - medea

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### Virtual

CNS 4490

Example

class One {

int a;

One(int a1){a = a1;}

int geta(){return a;}

virtual int times(){return 2*a;}

};

class Two : One

{

int b;

Two(int a1,int b1):One(a1){b=b1;}

override int times(){return b*a;}

};

class Three{

void main( ) {

One * joe = new One(4);

One * bob = new Two(5,3);

int c = bob.times( );

int d = joe.times();

}

};

d

c

bob

joe

bp

a

vtable

Example

class One {

int a;

One(int a1){a = a1;}

int geta(){return a;}

virtual int times(){return 2*a;}

};

class Two : One

{

int b;

Two(int a1,int b1):One(a1){b=b1;}

override int times(){return b*a;}

};

class Three{

void main( ) {

One * joe = new One(4);

One * bob = new Two(5,3);

int c = bob.times( );

int d = joe.times();

}

};

d

c

bob

joe

bp

[email protected]

b

a

vtable

a

vtable

Example

class One {

int a;

One(int a1){a = a1;}

int geta(){return a;}

virtual int times(){return 2*a;}

};

class Two : One

{

int b;

Two(int a1,int b1):One(a1){b=b1;}

override int times(){return b*a;}

};

class Three{

void main( ) {

One * joe = new One(4);

One * bob = new Two(5,3);

int c = bob.times( );

int d = joe.times();

}

};

d

c

bob

joe

[email protected]

bp

[email protected]

b

a

vtable

a

vtable

Example

class One {

int a;

One(int a1){a = a1;}

int geta(){return a;}

virtual int times(){return 2*a;}

};

class Two : One

{

int b;

Two(int a1,int b1):One(a1){b=b1;}

override int times(){return b*a;}

};

class Three{

void main( ) {

One * joe = new One(4);

One * bob = new Two(5,3);

int c = bob.times( );

int d = joe.times();

}

};

bp

ctrl lnk

this

retval

d

c

bob

joe

[email protected]

bp

[email protected]

b

a

vtable

a

vtable

Example

class One {

int a;

One(int a1){a = a1;}

int geta(){return a;}

virtual int times(){return 2*a;}

};

class Two : One

{

int b;

Two(int a1,int b1):One(a1){b=b1;}

override int times(){return b*a;}

};

class Three{

void main( ) {

One * joe = new One(4);

One * bob = new Two(5,3);

int c = bob.times( );

int d = joe.times();

}

};

bp

ctrl lnk

this

retval

bp

ctrl lnk

this

retval

d

c

bob

joe

[email protected]

bp

[email protected]

a

vtable

Example

; alloc space for joe

mov intreg, bp

mov r50, 8

int 41 ;int vector for alloc

; setup vtable

mov intreg, [bp]

mov r50,4

int 41

mov r1,[bp] ;

mov [r1], [email protected];

class One {

int a;

One(int a1){a = a1;}

int geta(){return a;}

virtual int times(){return 2*a;}

};

class Three{

void main( ) {

One * joe = new One(4);

One * bob = new Two(5,3);

int c = bob.times( );

int d = joe.times();

}

};

bp

ctrl lnk

this

retval

d

c

bob

joe

bp

[email protected]

a

vtable

Example

;set up call to Construtor

push done1

push [bp]

push 4

push bp

mov bp,sp

:done1

class One {

int a;

One(int a1){a = a1;}

int geta(){return a;}

virtual int times(){return 2*a;}

};

class Three{

void main( ) {

One * joe = new One(4);

One * bob = new Two(5,3);

int c = bob.times( );

int d = joe.times();

}

};

bp

ctrl lnk

a1

this

d

c

bob

joe

bp

[email protected]

a

vtable

Example

mov r1,this

mov [r1],[bp-8]

pop bp

sub sp,8

ret

:done1

class One {

int a;

One(int a1){a = a1;}

int geta(){return a;}

virtual int times(){return 2*a;}

};

class Three{

void main( ) {

One * joe = new One(4);

One * bob = new Two(5,3);

int c = bob.times( );

int d = joe.times();

}

};

bp

ctrl lnk

a1

this

d

c

bob

joe

bp

[email protected]

b

a

vtable

a

vtable

Example

; alloc space for bob

mov intreg, bp

mov r50, 12

int 41 ;int vector for alloc

; setup vtable

mov intreg, [bp]

mov r50,4

int 41

mov r1,[bp] ;

mov [r1], [email protected];

class Two : One

{

int b;

Two(int a1,int b1):One(a1)

{b=b1;}

override int times()

{return b*a;}

};

class Three{

void main( ) {

One * joe = new One(4);

One * bob = new Two(5,3);

int c = bob.times( );

int d = joe.times();

}

};

d

c

bob

joe

[email protected]

bp

[email protected]

b

a

vtable

a

vtable

Example

;set up call to Construtor

push done2

push [bp+4]

push 5

push 3

push bp

mov bp,sp

:done2

class Two : One

{

int b;

Two(int a1,int b1):One(a1)

{b=b1;}

override int times()

{return b*a;}

};

class Three{

void main( ) {

One * joe = new One(4);

One * bob = new Two(5,3);

int c = bob.times( );

int d = joe.times();

}

};

bp

ctrl lnk

b1

a1

this

d

c

bob

joe

[email protected]

bp

[email protected]

b

a

vtable

a

vtable

Example

:;set up call to [email protected]

push done3

push [bp-16]

push [bp-12]

push bp

mov bp,sp

:done3 ;Do Assignment

mov r1,[bp-16]

mov r1,[r1+8]

mov r2, [bp-8]

mov [r1], r2

ret

bp

ctrl lnk

a1

this

class One {

int a;

One(int a1){a = a1;}

int geta(){return a;}

virtual int times(){return 2*a;}

};

class Two : One

{

int b;

Two(int a1,int b1):One(a1){b=b1;}

override int times(){return b*a;}

};

class Three{

void main( ) {

One * joe = new One(4);

One * bob = new Two(5,3);

int c = bob.times( );

int d = joe.times();

}

};

bp

ctrl lnk

b1

a1

this

d

c

bob

joe

[email protected]

bp

[email protected]

b

a

vtable

a

vtable

Example

;set up call to [email protected]

push 0

push done4

push [bp+4]

push bp

mov bp,sp

mov r1,[bp+4]

jmp [r1]

:done4

class One {

int a;

One(int a1){a = a1;}

int geta(){return a;}

virtual int times(){return 2*a;}

};

class Two : One

{

int b;

Two(int a1,int b1):One(a1){b=b1;}

override int times(){return b*a;}

};

class Three{

void main( ) {

One * joe = new One(4);

One * bob = new Two(5,3);

int c = bob.times( );

int d = joe.times();

}

};

bp

ctrl lnk

this

retval

d

c

bob

joe

[email protected]

bp

[email protected]

b

a

vtable

a

vtable

Example

mov r1,[bp-8]

push [r1+8]

push [r1+4]

pop r2

pop r1

mul r1,r2

push r1

mov r1, bp-16

pop r2

mov [r1],r2

ret

class One {

int a;

One(int a1){a = a1;}

int geta(){return a;}

virtual int times(){return 2*a;}

};

class Two : One

{

int b;

Two(int a1,int b1):One(a1){b=b1;}

override int times(){return b*a;}

};

class Three{

void main( ) {

One * joe = new One(4);

One * bob = new Two(5,3);

int c = bob.times( );

int d = joe.times();

}

};

bp

ctrl lnk

this

retval

d

c

bob

joe