我写的C++代码错在哪了?
#include <iostream>using namespace std;
class student{
public:
student(int a=10,int b=5):at(a),bt(b){}
int sum;
private:
int at;
int bt;};
int student::sum(){
return(at*bt);}
int main(){
student stu[3]={
student(8,2),
student(7,6),
student(9,10),};
cout<<"stu[0]"<<stu[0].sum<<endl;
cout<<"stu[1]"<<stu[1].sum<<endl;
cout<<"stu[2]"<<stu[2].sum<<endl;
return 0;}
追问:D:\stu_test\bcszwj\c++\对象数组\对象数组.cpp(9) : error C2063: 'sum' : not a function
D:\stu_test\bcszwj\c++\对象数组\对象数组.cpp(9) : error C2040: 'sum' : 'int (void)' differs in levels of indirection from 'int'
D:\stu_test\bcszwj\c++\对象数组\对象数组.cpp(9) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.