码迷,mamicode.com
首页 > 编程语言 > 详细

c++中的struct

时间:2014-10-13 16:56:19      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   sp   数据   

c++中的struct不在是c中的struct,不仅仅是一个多个数据类型的结构体了。c++中的struct可以具有成员函数(c语言中是不可以的),c++ struct还可以继承class等等。同时c++中的struct还兼容c的struct。下面这篇文章写得很详细

C++中struct和class的区别

我也贴一段小代码吧

 1 #include <iostream>
 2 using namespace std;
 3 
 4 struct test_struct{
 5     int id;
 6     int age;
 7 
 8     void fun(){
 9         cout<<"id = "<<id<<"age = "<<age<<endl;//这里定义了成员函数
10     }
11 };
12 
13 int main(){
14     struct test_struct var1 = {1, 24};
15     printf("%d %d\n", var1.id, var1.age);
16 
17     return 0;
18 }

bubuko.com,布布扣

c++中的struct

标签:style   blog   http   color   io   os   ar   sp   数据   

原文地址:http://www.cnblogs.com/luckygxf/p/4022368.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!