virtual-functions Questions

9

Solved

Having at least one virtual method in a C++ class (or any of its parent classes) means that the class will have a virtual table, and every instance will have a virtual pointer. So the memory cost ...
Pernick asked 20/3, 2009 at 19:30

3

Solved

Is it possible for an inherited class to implement a virtual function with a different return type (not using a template as return)?

2

Solved

this is an example taken from Effective C++ 3ed, it says that if the static_cast is used this way, the base part of the object is copied, and the call is invoked from that part. I wanted to underst...
Resistencia asked 28/12, 2010 at 4:34

4

Solved

Consider the following code segment: class Window // Base class for C++ virtual function example { public: virtual void Create() // virtual function for C++ virtual function example { cout &l...
Mew asked 24/12, 2010 at 6:35

3

I'm writing an application that should process large ammounts of data (between 1-10 GB) as realtime as possible. the data is present in multiple binary data files on harddisk, each between few kb...
Don asked 10/11, 2010 at 9:26

2

Solved

I know that polymorphism can add a noticeable overhead. Calling a virtual function is slower than calling a non-virtual one. (All my experience is about GCC, but I think/heard that this is true for...
Listerism asked 6/11, 2010 at 2:24

5

Solved

Consider the following code (it's a little long, but hopefully you can follow): class A { } class B : A { } class C { public virtual void Foo(B b) { Console.WriteLine("base.Foo(B)"); } } cl...
Truthvalue asked 9/9, 2010 at 6:48

7

Solved

Consider the following: In X.h: class X { X(); virtual ~X(); }; X.cpp: #include "X.h" X::X() {} Try to build this (I'm using a .dll target to avoid an error on the missing main, and I'm u...
Fainthearted asked 24/8, 2010 at 20:34

5

Solved

I can't do this interface InterfaceA { void MethodA(); } class ClassA : InterfaceA { virtual void InterfaceA.MethodA() // Error: The modifier 'virtual' is not valid for this item { } } Whe...
Federico asked 26/7, 2010 at 16:57

2

Solved

In C++, a subclass can specify a different return type when overriding a virtual function, as long as the return type is a subclass of the original return type (And both are returned as pointers/re...

3

Solved

at my working place (php only) we have a base class for database abstraction. When you want to add a new database table to the base layer, you have to create a subclass of this base class and overr...
Tropho asked 28/8, 2009 at 22:14

5

Solved

Please consider the following code: class Abase{}; class A1:public Abase{}; class A2:public A1{}; //etc class Bbase{ public: virtual void f(Abase* a); virtual void f(A1* a); virtual v...
Stableman asked 23/6, 2010 at 15:38

2

Solved

Is there any compiler option in MS Visual C++ equivalent to GCC's -fdump-class-hierarchy? i.e. showing the virtual function table layout.
Urfa asked 13/6, 2010 at 18:16

7

Solved

#include <iostream> using namespace std; class Duck { public: virtual void quack() = 0; }; class BigDuck : public Duck { public: // void quack(); (uncommenting will make it compile) }; ...
Uneasy asked 2/6, 2010 at 13:16

7

A set of function pointers grouped into a data structure are often referred to as a virtual function table (VFT). The above statement makes me feel that virtual function == function pointer,...
Hube asked 23/5, 2010 at 12:40

2

Solved

In a typical implementation of the Visitor pattern, the class must account for all variations (descendants) of the base class. There are many instances where the same method content in the visitor ...

7

Solved

I have a question, here are two classes below: class Base{ public: virtual void toString(); // generic implementation } class Derive : public Base{ public: ( virtual ) void toString(); // ...
Underexpose asked 19/4, 2010 at 17:58

5

Solved

Consider this simple Java class: class MyClass { public void bar(MyClass c) { c.foo(); } } I want to discuss what happens on the line c.foo(). Original, Misleading Question Note: Not all of...
Mancuso asked 1/4, 2010 at 21:22

5

Solved

I have an array of custom class Student objects. CourseStudent and ResearchStudent both inherit from Student, and all the instances of Student are one or the other of these. I have a function to g...

4

I have the following code inside the .h file and I'm not sure what does the assignment statement do and how is it called properly? virtual void yield() = 0; I thought that the function returns a...
Physicalism asked 26/3, 2010 at 12:32

3

Solved

guys I know this question is very basic but I've met in few publications (websites, books) different style of override virtual function. What I mean is: if I have base class: class Base { public: ...
Hardfeatured asked 14/3, 2010 at 19:3

2

Solved

[All of the following was tested using Visual Studio 2008 SP1] In C++, const qualification of parameter types does not affect the type of a function (8.3.5/3: "Any cv-qualifier modifying a par...
Joab asked 9/3, 2010 at 22:32

2

Solved

Consider the following code: class A { public: virtual void f() throw ( int ) { } }; class B: public A { public: void f() throw ( int, double ) { } }; When compiled, it says that derived cla...
Exhibition asked 5/3, 2010 at 15:5

3

Solved

This is an extension for this question asked an hour ago. We cannot modify the access modifiers, when overriding a virtual method in derived class. Consider Control class in System.Web.UI namespac...
Robbierobbin asked 3/3, 2010 at 23:20

10

Solved

What is the difference member between function overriding and virtual functions in C++? Virtual member functions can be overridden in derived classes. Redefining a function in a derived class is ca...
Barmen asked 10/2, 2010 at 17:27

© 2022 - 2024 — McMap. All rights reserved.