Если вывожу два int'ыв числа, то все компилируется, и работает, но я хочу вывести строку через конструктор. Компилятор выдаёт ошибку:
source_file.cpp: In member function ‘void Human::Print()’:
source_file.cpp:38:44: error: ‘num’ was not declared in this scope
cout << "Age:" << age << " \tName:" << num << endl;
^~~
source_file.cpp:38:44: note: suggested alternative: ‘enum’
cout << "Age:" << age << " \tName:" << num << endl;
^~~
enum
source_file.cpp: In function ‘int main()’:
source_file.cpp:46:22: error: invalid conversion from ‘const char*’ to ‘char’ [-fpermissive]
Human a(20,"John");
^
source_file.cpp:10:3: note: initializing argument 2 of ‘Human::Human(int, char)’
Human(int setAge, char setName)
^~~~~
#include <iostream>
using namespace std;
class Human
{
private:
int age;
char name;
public:
Human(int setAge, char setName)
{
age = setAge;
name = setName;
}
int GetAge()
{
return age;
}
void SetAge(int setAge)
{
age = setAge;
}
int GetName()
{
return name;
}
void SetName(char setName)
{
name = setName;
}
void Print()
{
cout << "Age:" << age << " \tName:" << num << endl;
}
};
int main()
{
Human a(20,"John");
a.Print();
}