virtual-functions Questions

5

Solved

struct A { virtual void foo(); // unused and unimplemented virtual void bar () {} }; int main () { A obj; // ok obj.bar(); // <-- added this edition A* pm = (A*)malloc(sizeof(A)); // ok A...
Tatiania asked 3/6, 2011 at 17:12

3

I have a multiple inheritance scenario without virtual base classes like this: Ta Tb | | B C \ / A Ta and Tb are two different template classes that both declare a virtual function named f(...
Algae asked 6/5, 2011 at 12:51

4

Is there a way to change the virtual methods tables in C#? like change where a virtual method is pointing? class A { public virtual void B() { Console.WriteLine("B"); } } class Program { publ...
Heterogenous asked 1/5, 2011 at 14:13

8

Solved

Following this question, I'm wondering why a struct\class in C++ has to have a virtual method in order to be polymorphic. Forcing a virtual destructor makes sense, but if there's no destructor at ...
Foggia asked 29/4, 2011 at 12:13

6

Solved

From Addison Wesley: C++ Templates Member function templates cannot be declared virtual. This constraint is imposed because the usual implementation of the virtual function call mechanism us...
Weigle asked 21/4, 2011 at 10:4

5

Solved

Is it possible to access a function's v-table at runtime? Can meta-information such as the number of different function versions be determined? This might be more of a theoretical question, but cou...
Intendancy asked 21/4, 2011 at 5:59

1

So I want to allocate an object with virtual functions on the device, then call a kernel and execute some of those virtual functions. I have tried two ways to do this but neither work: 1) Allocate...
Transom asked 19/4, 2011 at 21:29

1

Solved

A library provides a class with virtual functions. Can this class be extended with new virtual functions without recompiling binaries dynamically linked to the library? I beleive this is not possi...

3

Solved

Assume the following simple case (notice the location of virtual) class A { virtual void func(); }; class B : public A { void func(); }; class C : public B { void func(); }; Would the follo...
Interlining asked 10/4, 2011 at 8:49

5

Imagine I have a class called Engine as an abstract base class. I also have ElectrictEngine and FuelEngine classes which derive from it. I want to create a method for refueling the engine. Should ...
Serpasil asked 8/4, 2011 at 15:12

3

Solved

Consider a scenario where there are two classes i.e. Base and Derived. If the Base class wants to call a function of the derived class, it can do so by either making a virtual function and defining...
Mauramauralia asked 6/4, 2011 at 10:12

6

Solved

C# methods in interfaces are declared without using the virtual keyword, and overridden in the derived class without using the override keyword. Is there a reason for this? I assume that it is jus...
Sorensen asked 1/9, 2010 at 19:21

3

Solved

How are virtual functions implemented in position-independent code? I know that if my class has virtual functions, the compiler usually generates a vtable for it that contains addresses of all vir...
Infrequency asked 21/3, 2011 at 12:21

3

Solved

#include <iostream> class base { public: virtual void print (int a) { std::cout << "a: " << a << " base\n"; } virtual void print (int a, int b) { std::cout <&l...
Hairbrush asked 21/3, 2011 at 0:29

9

Say I have a virtual function call foo() on an abstract base class pointer, mypointer->foo(). When my app starts up, based on the contents of a file, it chooses to instantiate a particular concrete...
Capillary asked 26/1, 2010 at 18:43

7

Solved

Possible Duplicate: C++: why is new needed? Why cant I use malloc to allocate space for my objects when they are children of a class containing virtual functions? This is really frust...
Renault asked 15/3, 2011 at 12:15

1

Solved

Why do I sometimes see in C++ examples when talking about subclassing / inheritance, the base class has virtual keyword and sometimes the overridden function has also the virtual keyword, why it's ...
Hipped asked 15/3, 2011 at 8:55

7

Solved

I have used the following C++ rule of thumb for a long time: If a class overrides a function in its base class, the function should be declared virtual in the base. I think I have come...
Given asked 13/3, 2011 at 13:50

2

Solved

Short Description: I am iterating over a vector calling a virtual function on every object in the vector in order to execute a sequence of actions. The vector is of the base class as is the iterato...
Mammoth asked 5/3, 2011 at 0:13

6

Solved

This is not a question about how they work and declared, this I think is pretty much clear to me. The question is about why to implement this? I suppose the practical reason is to simplify bunch of...
Sade asked 4/3, 2011 at 10:4

3

Solved

I'm having a bit of trouble using virtual functions in C++, and I might be misusing them in a constructor. The problem is that when linking a component lib (written by me) into my final executable,...
Pena asked 12/2, 2011 at 20:23

3

Solved

I noticed that If I run strings on my program which was compiled by g++ the output contains the names of various classes that it uses. The program was compiled with -O3 and without -g or -p, and ...
Adrienadriena asked 9/2, 2011 at 17:35

4

Solved

I just discovered that C++/CLI has a keyword that is not present (AFAIK) on standard C++: override. I don't know much about C++/CLI, so, can someone explain for which purpose is it included there...
Unpriced asked 28/1, 2011 at 19:42

4

Solved

I have two classes: class x { public: virtual void hello() { std::cout << "x" << std::endl; } }; class y : public x { public: void hello() { std::cout << "y" << std::...
Weinhardt asked 28/1, 2011 at 6:58

2

Solved

QUESTION 1) class Base { Base(std::string name); virtual std::string generateName(); } class Derived : Base { Derived(); virtual std::string generateName(); } here comes the question : w...
Psychopathology asked 26/1, 2011 at 12:8

© 2022 - 2024 — McMap. All rights reserved.