0

I have a following code

struct A { 
        int x;
A(int i) : x(i) {}
        virtual void a() {};
};

struct B: virtual A {
    B() : A(0) {}
    virtual void a(){} 
};

struct C: A, virtual B 
{
    virtual void a(){} 
    virtual void c(){}
};

The following code fails during the compilation
I add the C constructor C():A(1){} but the compilation still fails ...
Can somebody explain me what is the problem and how can I solve it?

Edited by Reverend Jim: Fixed formatting

3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by __avd
Featured Replies
  • 1

    [QUOTE=adatapost;920786] Use code tags. Source code must be surrounded with code tags. For example, [noparse] [CODE=C++] ... statements.. [/CODE] [/noparse][/QUOTE] You're wrong, it should be: [noparse] [CODE=cplusplus] ... statements.. [/CODE] [/noparse] Here's the difference: [code=c++] #include <iostream> using namespace std; int main(){ cout << "hai!"; } [/code] [code=cplusplus] #include <iostream> … Read More

0

Welcome bel050,
It would be virtual A.

struct C: virtual  A, virtual B
{
    C(): A(1) {}
   virtual void a(){}
   virtual void c(){}
};

Use code tags. Source code must be surrounded with code tags.
For example,

[CODE=C++] ... statements..

[/code]

0

I want the A to be non-virtual Base!

Edited by happygeek: fixed formatting

1

Use code tags. Source code must be surrounded with code tags.
For example,

[CODE=C++] ... statements..

[/code]

You're wrong, it should be:

[CODE=cplusplus] ... statements..

[/code]

Here's the difference:

#include <iostream>

using namespace std;

int main(){
    cout << "hai!";
}
#include <iostream>

using namespace std;

int main(){
    cout << "hai!";
}

See the difference in syntax-highlighting ? :)

Comments
I appreciate your suggestion.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.