virtual-functions Questions

3

Solved

So, based on a cursory search, I already know that calling a virtual function (pure or otherwise) from a constructor is a no go. I have restructured my code to ensure that I am not doing that. Whil...
Thicken asked 2/7, 2013 at 1:32

9

Solved

In brief: From a C++ base-class pointer which points to an instance of a derived class, how can one determine at run-time whether a non-pure virtual function (with an implementation in the base cla...
Schweiz asked 19/1, 2011 at 21:58

3

Solved

Could anyone be so nice and explain me why this code shows Derived.DoWork(double). I can come up with some explanations for this behaviour, however I want someone to clarify this for me. usi...
Satinet asked 12/5, 2014 at 17:34

3

Solved

The sample method below is intended to detect whether or not it has been overridden in a derived class. The error I get from MSVC implies that it is simply wrong to try to get the function pointer ...
Pya asked 26/11, 2009 at 6:50

3

Solved

This is not about "When VTABLE is created?". Rather, when the VPTR should be initialized? Is it at the beginning/end of the constructor or before/after the constructor? A::A () : i(0), j(0) -->...
Wilful asked 6/7, 2011 at 5:19

5

Solved

I know that for any class that has a virtual function or a class that is derived from a class that has a virtual function, the compiler does two things. First, it creates a virtual table for that c...
Dinorahdinosaur asked 28/10, 2011 at 20:28

2

Solved

I have the following C++ code illustrating virtual methods: class X{ O a; H b; virtual void c() = 0; virtual void d() = 0; }; class Y : public X{ virtual void c(); virtual void d(); }; wh...
Acie asked 8/3, 2014 at 1:40

6

Solved

I've been having a discussion with my coworkers as to whether to prefix overridden methods with the virtual keyword, or only at the originating base class. I tend to prefix all virtual methods (th...
Aschim asked 3/9, 2009 at 1:10

1

Solved

What is the ideologically correct way of implementing pure virtual methods in Python? Just raising NotImplementedError in the methods? Or is there a better way? Thank you!
Amphiaster asked 6/2, 2014 at 18:17

5

I am getting below warning . part of my code is : class Base { public: virtual void process(int x) {;}; virtual void process(int a,float b) {;}; protected: int pd; float pb; }; class derived:...
Bivins asked 30/1, 2014 at 17:7

1

Is there any replacement for 'fvtable-gc' options in GCCv4.7.1 (it was supported in GCCv3.x)? I want to remove unused virtual functions during linkage process. fvtable-gc Emit special relocatio...
Vercelli asked 3/7, 2013 at 10:44

4

Just starting to use Java. I find a lot of similarities with .NET, but I see that all methods in Java are virtual by default. So the question is what can I do to make them non virtual ? Is the fina...
Substituent asked 1/9, 2010 at 18:34

4

Solved

Surely the compiler is smart enough to deduce exactly what function you want for some cases, yet how come other cases require run-time support?
Julejulee asked 31/12, 2013 at 4:8

5

Solved

I have a litte confusion regarding method overriding and the validity of OOP priciples. I know everything regarding sealing, shadowing, overriding, virtual etc. but I came across a scenario, that j...
Cordova asked 21/12, 2013 at 9:48

2

Solved

Is it sufficient to define the method once to be virtual in the inheritance hierarchy to make polymorphism to work. In the following example Der::f is not defined to be virtual but d2->f(); prin...
Hereabouts asked 18/12, 2013 at 6:13

3

Solved

Consider following example #include <iostream> struct PureVirtual { virtual void Function() = 0; }; struct FunctionImpl { virtual void Function() { std::cout << "FunctionImpl:...
Topgallant asked 12/12, 2013 at 16:8

1

Solved

I had to design and develop a C++ module which will be used in a real time environment (it will be run on a modern multi-core PC). When I designed it I created C++ interfaces (classes with only pur...
Garb asked 7/12, 2013 at 7:53

4

Solved

Have seen some related questions, but not this exact one... I've treated classes as fitting into a few major categories, let's say these four for simplicity: Value Classes which have some data a...
Pizzeria asked 4/11, 2013 at 17:45

3

Solved

Consider the following code: #include <iostream> #include <typeinfo> #include <type_traits> using namespace std; struct A { int data; }; struct B1 : A {}; struct B2 : virtual A...
Serafinaserafine asked 24/11, 2013 at 12:20

3

Solved

In C++, during dynamic binding, consider the following example... class Base { virtual void fun() { cout<<"Base"; } }; class Derived : public Base { void fun() { cout<&l...
Cutwork asked 7/10, 2013 at 11:49

4

Solved

Is it good practice to make a base class constructor protected if I want to avoid instances of it? I know that I could as well have a pure virtual dummy method, but that seems odd... Please consid...
Corissa asked 30/9, 2013 at 9:8

5

Solved

Is there any way to call write generic programs and algorithms in C# while avoiding the overhead of a dynamic solution? Consider a simple example: static void QuickSort<T>(T[] arr, int left...
Phono asked 9/2, 2012 at 3:9

6

I'm evaluating to rewrite a piece of real-time software from C/assembly language to C++/assembly language (for reasons not relevant to the question parts of the code are absolutely necessary to do ...
Quirt asked 23/8, 2013 at 14:12

5

Solved

I understand that C++ implements runtime polymorphism thorugh virtual functions and that virtual keyword is inherited but I don't see use of virtual keyword in derived class. e.g. In below case ev...
Slippy asked 7/8, 2013 at 13:4

6

Solved

Ah, SO came back just in time. I am getting a strange error: 'B::blah': overriding virtual function return type differs and is not covariant from 'A::blah' Here is the code causing the problem...
Hypostasize asked 6/8, 2011 at 21:27

© 2022 - 2024 — McMap. All rights reserved.