I am a newbie in C++. I wrote this code to understand the difference between public
, protected
and private
. The problem is, when I create an object of Hund4
, I get this error:
use of deleted function
This error is in the last line.
Can you please help me to solve this problem?
#include <iostream>
#include <iostream>
#include <string>
using namespace std;
class Tier
{
public:
void wieMachtDasTier()
{
cout << "Hello\n";
}
protected:
void foo()
{
cout << "foo\n";
}
private:
void baz()
{
cout << "baz\n";
}
};
class Hund: public Tier
{
private:
string name;
public:
Hund(string newname):name(newname){}
string getname()
{
return this->name;
}
void test()
{
foo();
}
};
class Hund2: protected Tier
{
public:
void test()
{
foo();
}
};
class Hund3: private Tier
{
public:
void test()
{
foo();
}
};
class Hund4 : public Hund
{
};
int main()
{
Hund ace("ace");
ace.wieMachtDasTier();
Tier Haustier;
ace.test();
Hund2 ace2;
ace2.test();
Hund3 ace3;
ace3.test();
Hund4 ace4;
return 0;
}