main.cpp:46:1: error: ‘ma’ does not name a type wie beheben?
#include <iostream>
#include <string>
using namespace std;
class Person{
private:
string name;
int alter;
public:
void zeigePerson();
Person(string n,int a){
name=n;
alter=a;
}
};
void Person::zeigePerson(){
std::cout << name << std::endl;
std::cout << alter << std::endl;
};
class Mitarbeiter : Person{
private:
int gehalt;
public:
void gehaltAendern(int g){
gehalt=g;
}
Mitarbeiter(string name,int alter,int gehalt):Person(name,alter){
gehalt=gehalt;
}
void zeigePerson();
};
void Mitarbeiter::zeigePerson(){
Person::zeigePerson();
std::cout << gehalt << std::endl;
}
Person ma(“mario”,20);
ma.zeigePerson();
int main()
{
return 0;
You have taken the code out of the main block and as an independent block according to the definition of the class
written. The compiler cannot recognize that
Type
is because this code is outside a function and thus does not contain instructions.
In order to run the code, you need the instance of
move to the main function and the method
call. The corrected code looks as follows:
Now the code should compile and run without errors.
#include
#include
using namespace std;
class person
private:
string name;
int old;
public:
void showperson();
Person(string n, int a) {
name = n;
age = a;
}
};
void Person::Learn() {
std::cout < < < name < < < < < < std::endl;
std::cout < < < < < < < < < < < < < < < < < < < < < :: endl;
}
class Staff : Person {
private:
int content;
public:
void content Changes(int g) {
content = g;
}
Staff(string name, int old, int grade) : Person(name, old) {
this > content = content;
}
void showperson();
};
void Staff::Learn() {
Person:: showperson();
std::cout < < < < < < < < < < < < < < < stdd:: endl;
}
int main() {
Person ma(“mario”, 20);
the person(s);
return 0;
}
OMG as stupid of me. we couldn’t see that haha.