in this program, I am interested by this problem: how to access to the variable building and I do not understand errors:
gcc struct1En.cc -lstdc++ -o struct1En
struct1En.cc: In member function 'void job::cie::printBuilding()':
struct1En.cc:22: error: 'job' is not a base of 'job::cie'
struct1En.cc: In function 'int main()':
struct1En.cc:48: error: incompatible types in assignment of 'const char [10]' to 'char [20]'
I read people use class rather than struct. But in this case I just want to know why I can not reach the variable building and why the error say incompatible types in assignment of 'const char[10] to 'char [20]'
#include <iostream>
struct job {
private:
char name[20];
double salary;
public:
int building;
void initName() {std::cin >> name;}
void initSalary() {std::cin >> salary;}
void printName() {std::cout << "name: " << name << std::endl;}
void printSalary() {std::cout << "Salary: " << salary << std::endl;}
void printBuilding() {std::cout << "Building number : " << building << std::endl;}
struct cie {
char name[20];
int employee;
void printName(){ std::cout << "name: " << cie::name << std::endl;}
void printEmployee() {std::cout << "number of employees : " << employee << std::endl;}
void printBuilding() {std::cout << "Building number: " << this->job::building << std::endl;}
};
};
int main() {
job teacher;
std::cout << "Enter a name: \n";
std::cout << "Name: ";
teacher.initName();
teacher.printName();
std::cout << "Enter a salary: \n";
std::cout << "Salary: ";
teacher.initSalary();
teacher.printSalary();
std::cout << "Enter the number of the building: \n";
std::cout << "Building n°: ";
std::cin >> teacher.building;
teacher.printBuilding();
job::cie educationNationale;
educationNationale.name = "Courriere";
educationNationale.printName();
educationNationale.employee = 200 + 1;
educationNationale.printEmployee();
educationNationale.printBuilding();
return 0;
}