#include <string>
#include <iostream> // для объекта cout
usingnamespace std;
class Cat {
public:
Cat(int initialAge = 5);
~Cat();
int GetAge() const; // метод доступа const функция доступа к данным-членам класса без права их изменения
void SetAge(int age);
//void Meow();
void Wydam() {
Bam();
}; //статический метод
int Bgsamm();
Cat() {
itsAge = 0;
B = 8;
};
private:
int itsAge; // статические переменные класса (Статическое поле)
int B;
void Bam() {
cout << "Wydam\n";
int BG = itsAge + B;
cout << BG;
}
};
int Cat::GetAge() const {
return itsAge;
}
// конструктор класса Cat
Cat::Cat(int initialAge) {
itsAge = initialAge;
cout << "Cat constructor\n";
}
Cat::~Cat() // деструктор, который не выполняет никаких действий
{
cout << "Cat destructor\n";
}
int Cat::Bgsamm() {
return (itsAge++);
}
int main(int argc, char** argv) {
Cat c();
cout << c.GetAge();
return 0;
}
Next time, you should point out the line the error is for.
The problem, on line 56, is because of the parentheses. You do not call the default constructor like that. The compiler will interpret it as a function prototype, where the function's name is c, takes no arguments, and returns a Cat object.
Because your Cat(int) constructor has a default argument, which lets you call it without arguments.
This allows you to call it like so:
Cat c = Cat();
But here comes the problem: which constructor should be called? Do you want the constructor that takes no arguments Cat()? Or do you want to call the constructor that takes an int Cat(int), for which 5 has been provided?
You can look at these functions as an example:
1 2 3 4 5 6
void funky(char c, int I = 5){
cout << c << I < '\n';
}
void funky(char c){
cout << c << '\n';
}
If you write funky('a'), do you want just 'a' to be printed, or both 'a' and 5?
You don't really need Cat(). Cat(int = 5) would serve fine as a default constructor.