virtual-functions Questions
1
Solved
I am trying to build a service object which can run (i.e. execute it's run() function) in a separate thread. This is the service object
#include <boost/noncopyable.hpp>
#include <atomic&g...
Madgemadhouse asked 17/7, 2015 at 23:24
2
Solved
I thought I understood inheritance, and virtual functions, and function overloading, but I've got a case where something about the interplay between these features is eluding me.
Suppose I've got ...
Glair asked 7/7, 2015 at 14:35
1
Solved
I have a simple program:
struct B
{
virtual ~B() {}
};
struct D : public B
{
~D() {}
};
So, when I call
B* b = new D;
b->~B();
why is the destructor of the derived class called? It's ...
Clymer asked 1/7, 2015 at 8:7
5
Solved
Given the following code fragment, what are the differences in the function calls? What is function hiding? What is function overriding? How do they relate to function overloads? What is the differ...
Leffert asked 1/11, 2013 at 22:15
3
Solved
In C++, it's possible to get a pointer to a (non-static) member function of a class, and then later invoke it on an object. If the function was virtual, the call is dispatched dynamically depending...
Thorrlow asked 21/2, 2011 at 10:8
1
Having
#include <iostream>
using namespace std;
class A {
public:
virtual void foo() {
cout << "A" << endl;
}
};
class B : public A {
public:
void foo() {
cout << "...
Trapani asked 18/6, 2014 at 12:55
5
Virtual function calls can be slow due to virtual calls requiring an extra indexed deference to the v-table, which can result in a data cache miss as well as an instruction cache miss... Not good f...
Vigor asked 27/6, 2013 at 13:39
2
Consider the following code with a template method design pattern:
class A {
public:
void templateMethod() {
doSomething();
}
private:
virtual void doSomething() {
std::cout << “42\n”...
Goldfish asked 18/12, 2014 at 5:10
2
Solved
I'm attempting to use std::enable_if to specialise a class if one of it's subclasses has a specific member function defined. Otherwise it should use a default implementation that is defined in the ...
Gerita asked 15/12, 2014 at 17:2
2
I am having hard time to undertsand what constitutes the size of following classes?
I am using MSVS 2008 (VC 9.0 compiler).
I have read that if I do not declare virtual functions(in below example)...
Leith asked 28/2, 2014 at 9:34
11
C++ supports dynamic binding through virtual mechanism. But as I understand the virtual mechanism is an implementation detail of the compiler and the standard just specifies the behaviors of what s...
Umbilical asked 4/12, 2010 at 5:2
5
Solved
While playing with implementing a virtual assignment operator I have ended with a funny behavior. It is not a compiler glitch, since g++ 4.1, 4.3 and VS 2005 share the same behavior.
Basically, th...
Treadwell asked 9/6, 2009 at 10:20
5
Assignment Operator in C++ can be made virtual. Why is it required? Can we make other operators virtual too?
Touter asked 21/3, 2009 at 19:28
1
Solved
Code Sample:
Consider the following diamond hierarchy:
struct A
{
virtual void f(){}
void g(){}
};
struct B : virtual A
{
virtual void f() override{}
void g(){}
};
struct C : virtual A
{
}...
Mum asked 10/11, 2014 at 22:49
1
Solved
I see that CUDA doesn't allow for classes with virtual functions to be passed into kernel functions. Are there any work-arounds to this limitation?
I would really like to be able to use polymorphi...
Leahy asked 8/11, 2014 at 2:2
1
Solved
Here’s a class with an undefined method. It seems compilers allow instances of this class to be constructed, so long as the undefined member function is never called:
struct A {
void foo();
};
i...
Straightjacket asked 7/11, 2014 at 22:45
3
Solved
header.h
#include <iostream>
using namespace std;
class A
{
public:
virtual void display(int i=5) { cout<< "Base::" << i << endl; }
};
class B : public A
{
publi...
Dispart asked 23/9, 2014 at 12:0
4
Solved
I have C++ class with multiple parents; each parent defines a function with a common name but a different purpose:
class BaseA
{
virtual void myFunc(); // does some task
};
class BaseB
{
virtual ...
Thundersquall asked 30/3, 2011 at 2:53
3
Solved
I've read about virtual functions in C++ and understood how they provide the programmer with access to the member function of derived class using a pointer of base class. (aka Polymorphism).
The q...
Dewaynedewberry asked 2/9, 2014 at 13:11
2
Solved
The sample code are as follow:
class A
{
public:
int k;
virtual int f();
};
class B:public virtual A
{
public:
virtual int a();
};
int main()
{
cout<<sizeof(A)<<sizeof(B);
}
It p...
Letterperfect asked 27/8, 2014 at 8:59
4
Solved
If the virtual function table is the same for all objects of the class, then why can't the pointer to that table (vfptr) be static and be shared across all the objects?
Sump asked 23/8, 2014 at 16:2
1
Solved
although I've been helped countless times by other questions/answers here, this is my first question here, so don't be too harsh on me! :)
I've been learning QT/C++ and let's assume I have somethi...
Nasia asked 18/8, 2014 at 16:32
3
Solved
I know that the override contextual keyword was introduced to write safer code (by checking for a virtual function with the same signature) but I don't feel good about it, because it seems to be re...
Klemens asked 30/7, 2014 at 10:30
3
Solved
Normally calling virtual functions from constructors is considered bad practice, because overridden functions in sub-objects will not be called as the objects have not been constructed yet.
But, C...
Whitish asked 30/6, 2014 at 17:6
1
Solved
Hence I have a class, and want to determine whether it has a virtual function or not.
The first way to do I considered by dynamic cast.
class A
{
// hidden details..
};
class B:public ...
Sacrosanct asked 10/6, 2014 at 12:27
© 2022 - 2024 — McMap. All rights reserved.