virtual-functions Questions
2
Solved
Compare the following code in C++:
#include <iostream>
#include <vector>
struct A
{
virtual void bar(void) { std::cout << "one" << std::endl; }
};
struct B : public A
{
...
Blinders asked 5/8, 2016 at 1:43
4
Solved
Is it possible to have the observed behavior of a program changed by simply adding a new virtual function to a base class? I mean that no other change must be made to the code.
Pamphlet asked 29/7, 2016 at 11:19
4
My problem is this: I have an interface root class with several concrete branch classes. In application code, there exists a vector of pointers to the root class. There are several places where I n...
Goulder asked 9/7, 2016 at 19:9
3
Solved
We can't create an object of an abstract class, right? So how can I call a virtual function which has definition in both abstract base class and derived class? I want to execute the code in abstrac...
Rozamond asked 24/6, 2016 at 9:41
2
Solved
I have a class ('TestC'), which is derived from two other classes ('TestA' and 'TestB'), both of which have a virtual function with the same signature.
To make the function accessible through 'Tes...
Hypethral asked 3/6, 2016 at 9:49
3
Solved
This is maybe a fine point, but it concerns the warning that the compiler issues if you do something like:
class A
{
public virtual void F() { }
}
class B : A
{
public void F() { }
}
Then you ...
Peaceful asked 9/5, 2011 at 5:54
2
The following code is late binding test() method but shouldn't it bind early? because test() method is not virtual in class B(but in class A), and we are using pointer of class B.
class A{
...
Geneticist asked 12/5, 2016 at 9:30
2
I was under the impression that whenever you do one of these:
Add a new public virtual method virtual void aMethod();
Add a new public non-virtual method void aMethod();
Implement a public pure-v...
Impuissant asked 10/5, 2016 at 21:43
4
Solved
I'm trying to get an understanding of object oriented style programming in Haskell, knowing that things are going to be a bit different due to lack of mutability. I've played around with type class...
Backwoods asked 25/11, 2013 at 3:31
4
Solved
class base {
public:
void virtual fn(int i) {
cout << "base" << endl;
}
};
class der : public base{
public:
void fn(char i) {
cout << "der" << endl;
}
};
int main()...
Anvil asked 2/2, 2012 at 9:11
1
Solved
I have such hierarchy of classes:
template <class Type>
class CrtpBase
{
protected:
Type& real_this()
{
return static_cast<Type&>(*this);
}
};
template <class ChildType...
Pulverable asked 15/4, 2016 at 8:49
2
Solved
I am self-taught, and therefore am not familiar with a lot of terminology. I cannot seem to find the answer to this by googling: What is a "virtual" vs a "direct" call to a virtual function?
This...
Gumma asked 12/4, 2016 at 21:46
7
Solved
I recently came to know that in C++ pure virtual functions can optionally have a body.
What are the real-world use cases for such functions?
Fagaly asked 9/4, 2010 at 16:52
5
Solved
As I understand it, the override keyword states that a given declaration implements a base virtual method, and the compilation should fail if there is no matching base method found.
My understandi...
Fiche asked 2/4, 2015 at 11:58
1
Background
Recently, a colleague of mine ran into a problem where an old version of a header file for a library was used. The result was that the code generated for calling a virtual function in a...
Jaban asked 18/11, 2015 at 9:26
2
Solved
Suppose I have class A with a virtual function F():
class A
{
virtual void F()
{
// Do something
};
};
And I have another class B which inherits A and redefines F():
class B : A
{
void F()...
Crescin asked 19/2, 2016 at 13:45
12
Solved
Is there ever a good reason to not declare a virtual destructor for a class? When should you specifically avoid writing one?
Petry asked 19/11, 2008 at 4:27
3
Solved
Here is the class definition:
class Shape { public:
virtual void draw() = 0; ...
};
class Circle : public Shape {
public:
void draw() { ... }
... };
class Rectangle : public Shape { public:
vo...
Mitrailleuse asked 13/1, 2016 at 11:51
5
Solved
This is in fact an interview question, I can't figure out the answer. Anyone knows about this?
You can talk about any difference, for example, the data that are push into stack.
Scourge asked 8/1, 2012 at 9:18
1
Solved
I have an abstract class that is declared as follow:
class my_type {
public:
virtual ~my_type() = default;
virtual void do_something() = 0;
};
Is it considered good practice to declare the des...
Rolph asked 20/12, 2015 at 17:5
15
Solved
In my class design, I use abstract classes and virtual functions extensively. I had a feeling that virtual functions affects the performance. Is this true? But I think this performance difference i...
Microprint asked 16/1, 2009 at 8:22
1
Solved
So far as I understand, virtual method calls are late binding and thus cannot be inlined by the compiler. Apparently, nvcc relies heavily on inlining code. I'm wondering if virtual methods have any...
Oberland asked 13/11, 2015 at 10:6
2
Solved
Let's say we have more than one virtual function in the parent class and derived class. There will be a vtable created for these virtual functions in the vtable for both the parent derived class.
...
Prosecutor asked 8/10, 2015 at 2:57
2
Solved
#include <iostream>
struct A {
void init()
{
internal_init();
}
virtual void internal_init()
{
std::cout << "internal of A" << std::endl;
}
};
struct B: public A {
void...
Glyptic asked 15/9, 2015 at 14:11
3
Solved
n3797 says:
§ 7.1.6.4/14:
A function declared with a return type that uses a placeholder type
shall not be virtual (10.3).
Therefore the following program is ill-formed:
struct s
{
virtual...
Scruff asked 9/10, 2014 at 0:55
© 2022 - 2024 — McMap. All rights reserved.