类中包含结构体的参数初始化

# include <iostream>
using namespace std;
struct St
{	
	int a;
	float b;

};
class CStu
{
public:
	St st;
	CStu(St st0):st(st0)
	{
		cout<<st0.a<<"         "<<st0.b<<endl;
	}
	void show()
	{
		cout<<st.a<<"         "<<st.b<<endl;
		
	}
};


int main()
{
	St st0 = {5,12.5f};
	CStu stu(st0);
	stu.show();
	

	
	cout<<"         "<<sizeof(3.5f)<<endl;
	cout<<"hello world"<<endl;
	system("pause");
    return 0;
}
发布了114 篇原创文章 · 获赞 28 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/ChaoFeiLi/article/details/103527373