注册 登录
编程论坛 C++教室

为什么代码对了,编译器说有很多错误运行不出来

z1842670133 发布于 2021-12-23 22:41, 997 次点击
#include<iostream>
using namespace std;
#include<string>
template<class T1,class T2>
class Person
{
public:   
Person(T1 name,T2 age)
    {
        this->m_Name = name;   
        this->m_Age = age;   
    }
    void showPerson()   
   {        
        cout << "姓名" << this->m_Name << "年龄" << this->m_Age << endl;   
   }   
       T1 m_Name;   
       T2 m_Age;
};
void printPerson1(Person<string,int>&p)
{
    p.showPerson();
}
void test01
{   
    Person<string,int>p("孙悟空",100);
    printPerson1(p);
}
int main()
{   
    test01();   
    system("pause");
    return 0;
}
1 回复
#2
rjsp2021-12-24 07:51
为什么代码对了,编译器说有很多错误
呵呵,把你的错误代码“void test01”改正为“void test01()”再试试
1