Good afternoon. I tried to translate the warning from portuguese to english.
edit: I figured out
Code:
thames@semaht ~/C++ $ g++ -g -Wall inheritance.cpp -o inheritance
inheritance.cpp: Na função membro ‘void Derived1Level1::f(char*)’:
inheritance.cpp:32:21: warning: conversão obsoleta de constante string para ‘char*’ [-Wwrite-strings]
inheritance.cpp:33:21: warning: conversão obsoleta de constante string para ‘char*’ [-Wwrite-strings]
inheritance.cpp: Na função membro ‘void Derived2Level1::f(char*)’:
inheritance.cpp:48:23: warning: conversão obsoleta de constante string para ‘char*’ [-Wwrite-strings]
inheritance.cpp: Na função membro ‘void DerivedLevel2::f(char*)’:
inheritance.cpp:59:21: warning: conversão obsoleta de constante string para ‘char*’ [-Wwrite-strings]
inheritance.cpp:60:37: warning: conversão obsoleta de constante string para ‘char*’ [-Wwrite-strings]
inheritance.cpp:61:32: warning: conversão obsoleta de constante string para ‘char*’ [-Wwrite-strings]
inheritance.cpp: Na função ‘int main()’:
inheritance.cpp:72:17: warning: conversão obsoleta de constante string para ‘char*’ [-Wwrite-strings]
inheritance.cpp:75:19: warning: conversão obsoleta de constante string para ‘char*’ [-Wwrite-strings]
inheritance.cpp:77:19: warning: conversão obsoleta de constante string para ‘char*’ [-Wwrite-strings]
inheritance.cpp:78:19: warning: conversão obsoleta de constante string para ‘char*’ [-Wwrite-strings]
inheritance.cpp:81:18: warning: conversão obsoleta de constante string para ‘char*’ [-Wwrite-strings]
inheritance.cpp:83:9: warning: conversão obsoleta de constante string para ‘char*’ [-Wwrite-strings]
thames@semaht ~/C++ $
Code:
#include <iostream>
using namespace std;
class BaseClass {
public:
BaseClass() {}
void f(char *s = "unknown")
{
cout << "Function f() in Baseclass called from " << s << endl;
h();
}
protected:
void g(char *s = "unknown")
{
cout << "Function g() in BaseClass called from " << s << endl;
}
private:
void h()
{
cout << "Function h() in BaseClass\n";
}
};
class Derived1Level1: public virtual BaseClass
{
public:
void f(char *s = "unknown")
{
cout << "Function f() in Derived1Level1 called from " << s << endl;
g("Derived1Level1");
h("Derived1Level1");
}
void h(char *s = "unknown")
{
cout << "Function h() in Derived1Level1 called from " << s << endl;
}
};
class Derived2Level1: public virtual BaseClass
{
public:
void f(char *s = "unknown")
{
cout << "Function f() in Derived1Level1 called from " << s << endl;
g("Derived2Level1");
// h() // error: BaseClass::h() is not accessible
}
};
class DerivedLevel2: public Derived1Level1, public Derived2Level1
{
public:
void f(char *s = "unknown")
{
cout << "Function f() in DerivedLevel2 called from " << s << endl;
g("DerivedLevel2");
Derived1Level1::h("DerivedLevel2");
BaseClass::f("DerivedLevel2");
}
};
int main(void)
{
BaseClass bc;
Derived1Level1 d1l1;
Derived2Level1 d2l1;
DerivedLevel2 dl2;
bc.f("main(1)");
// bc.g(); // error: BaseClass::g() is not accessible
// bc.h(); // error: BaseClass::h() is not accessible
d1l1.f("main(2)");
// d1l1.g();
d1l1.h("main(3)");
d2l1.f("main(4)");
// d2l1.g();
// d2l1.h();
dl2.f("main(5)");
// dl2.g();
dl2.h();
return 0;
}