0
我在一個名爲cpp.sh的在線C++網站上玩耍,並開始測試我在課堂上的技能,我遇到了一個錯誤,我可以使用一些幫助。錯誤說我的代碼中的'Person'和'p1'沒有在這個範圍內聲明,但我正在查找類的Youtube上的教程,代碼看起來很好。任何幫助表示讚賞。代碼如下。前main
功能People
類的對象和類和未聲明的範圍C++問題
#include <iostream>
#include <string>
using namespace std;
int main() {
int age;
string name;
cout << "Enter name: " << endl;
cin >> name;
cout << "Enter age: " << endl;
cin >> age;
Person p1;
p1.test(name,age);
return 0;
}
class Person{
public:
void test(string name,int age){
cout << name << " is " << age << " years old." << endl;
}
};