Help with build errors
I am using Xcode. For some reason I am getting errors with the following code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <iostream>
#include <string>
using namespace std;
class A
{
public:
A() : m_msg("Apple") {}
A(string msg) : m_msg(msg) {}
virtual ~A() { message(); }
void message() const
{
cout << m_msg << endl;
}
private:
string m_msg;
};
class B : public A
{
public:
B() : A("Apple") {}
B(string msg) : A(msg), m_a(msg) {}
void message() const
{
m_a.message();
}
private:
A m_a;
};
int main() {
A *b1 = new B;
B *b2 = new B;
A *b3 = new B("Apple");
b1->message();
// error: expected `;' before 'OTHER' token
b2->message();
// error: expected `;' before 'OTHER' token
b3->message();
// error: expected `;' before 'OTHER' token
delete b1;
delete b2;
delete b3;
}
|
Any help would be greatly appreciated.
class B : public virtual A
Topic archived. No new replies allowed.