FAQ Database Discussion Community


what does compiler do when new an object and assign the address of the created object to its base class pointer

c++,multiple-inheritance,virtual-functions
Example 3:(page 377) class A {virtual void f();}; class B {virtual void f(); virtual void g();}; class C: A, B {void f();}; A* pa = new C; B* pb = new C; C* pc = new C; pa->f(); pb->f(); pc->f(); pc->g() (1) In Multiple inheritance for C++, Bjarne wrote: On...

C++ rules for covariant virtual function

c++,c++11,virtual-functions
I was reading Covariant virtual function. It says that Suppose that B::f overrides the virtual function A::f. The return types of A::f and B::f may differ if all the following conditions are met: 1) The const or volatile qualification of the pointer or reference returned by B::f has the same...

C++ Virtual Functions Acting Weird

c++,inheritance,virtual-functions
I am trying to understand virtual functions as well as virtual inheritance. For the most part, I think I successfully grasp it and its relation to polymorphism, I have been reading how the vptr works with derived objects and what not, however the example below is throwing me off, it...

understanding of multiple inheritance for c++

c++,this,multiple-inheritance,virtual-functions,vtable
I'm reading multiple inheritance for c++ An Example in the paper:(page 377) class A {virtual void f();}; class B {virtual void f(); virtual void g();}; class C: A, B {void f();}; A* pa = new C; B* pb = new C; C* pc = new C; pa->f(); pb->f(); pc->f(); pc->g()...

What does a non-trivial copy constructor do? [duplicate]

c++,copy-constructor,virtual-functions
This question already has an answer here: What is a non-trivial constructor in C++? 3 answers In C++, if a copy constructor is not defined the compiler will do that for you. If one is defined, compiler would not. The compiler generated copy constructor can be trivial or non-trivial....

compiler's detail of this pointer, virtual function and multiple-inheritance

c++,pointers,multiple-inheritance,virtual-functions,this-pointer
I'm reading Bjarne's paper: Multiple Inheritance for C++. In section 3, page 370, Bjarne said that "The compiler turns a call of a member function into an "ordinary" function call with an "extra" argument; that "extra" argument is a pointer to the object for which the member function is called."...

Pattern for choosing behaviour based on the types present in a collection derived objects

c++,oop,inheritance,design-patterns,virtual-functions
I have an collection of objects which represents a model of a system. Each of these objects derives from a base class which represents the abstract "component". I would like to be able to look at the system and choose certain behaviours based on what components are present and in...

virtual function in c++ need an implemetation without implemetation its giving an error

c++,virtual-functions
#include <iostream> using namespace std; class A{ public: int a; virtual void fun(); }; int main(){A obj;} getting error undefined reference to 'vtable for A'. I want to know why without implement virtual function giving this type of error....

Determine the size of object without it's virtual table pointers

c++,virtual-functions
Is there a generic way (not platform dependent) to get at compile time the size of a class object in the memory, without counting the vtable pointers? Thanks!...

Conflicting type attributes specified for virtual destructor

c++,inheritance,g++,virtual-functions,calling-convention
The following extract was previously compiling under Borland C++, MSVC and OpenWatcom: class aaa { virtual _fastcall ~aaa(); }; class bbb:public aaa { }; It doesn't compile under gcc/g++ (MinGW 4.8.0). Error: probz.cpp:7:7: error: conflicting type attributes specified for 'virtual bbb::~bbb()' class bbb:public aaa { ^ probz.cpp:3:20: error: overriding 'virtual...

Is it safe to declare non-virtual destructor in the derived class

c++,inheritance,destructor,virtual-functions
In the program: struct A { virtual ~A(){ } }; struct B : A { ~B(){ } }; int main(){ } The Standard N4296::12.4/9: If a class has a base class with a virtual destructor, its destructor (whether user- or implicitly-declared) is virtual. So, the compiler will redeclare the destructor...

Unhandled Exception when using abstract function

c++,opengl,virtual-functions
I'm trying to load in a basic shader using within my program, but after it's loaded, I get an Unhandled Exception popup box. I've created a base class to do all the common parts of loading a generic shader. within the base class, I have a protected virtual function and...