使用c++版本:201703
测试代码:
#include<iostream>
using namespace std;
struct A {
public:
A(int x,int y) {
val1 = x;
val2 = y;
}
int sum() {
return val1 + val2;
}
~A(){
cout<<" do nothing!"<<endl;
}
int val1;
int val2;
};
int main()
{
cout<< __GNUC__ << endl;
cout<< __cplusplus << endl;
A a{2,3};
A b{1,2};
cout << a.val1 << "\t" << a.val2;
}
根据网上搜索:
该版本c++中,struct与class的不同是,struct默认构造为public,继承默认也是public,class默认为private。
不能在模板中使用struct。