我是 cpp 语言的新手,我的代码有问题,我不知道如何解决,我在这里查看了人们提出的有关此错误的其他一些问题,但没有一个答案真正帮助我解决问题。所以这是我的主要功能:
#include <iostream>
#include "Person.h"
#include <string>
int main() {
Person p2();
Person p1();
std::cout << p1.toString() << std::endl;
return 0;
}
这是我的 Person.h 文件:
#ifndef PERSON_H_
#define PERSON_H_
#include <string>
class Person {
private:
int age;
std::string name;
int numOfKids;
public:
Person() {
this->age = 0;
this->name = "bob";
this->numOfKids = 5;
}
Person(int agee, std::string namee, int numof);
~Person();
std::string toString();
};
#endif // PERSON_H_
在主函数中,它标记p1.toString()并说“表达式必须具有类类型”,我不知道该怎么做,我尝试了很多东西,但都没有奏效。