载入中。。。 'S bLog
 
载入中。。。
 
载入中。。。
载入中。。。
载入中。。。
载入中。。。
载入中。。。
 
填写您的邮件地址,订阅我们的精彩内容:


 
VC++学习笔记4 - 类
[ 2010/7/5 15:56:00 | By: 梦翔儿 ]
 

// 类定义与使用
//
#i nclude "stdafx.h"
#i nclude "iostream"
#i nclude "string"
using namespace std;

class student
{
public:
 string Name;
 int age;
 bool IsBoy;
};

void print(student stu)
{
 cout<<stu.Name<<endl;
}
=========
// 类的成员函数
//
#i nclude "stdafx.h"
#i nclude "iostream"
#i nclude "string"
using namespace std;

struct color
{
 unsigned char red;
 unsigned char blue;
 unsigned char green;
};

class car
{
public:
 char id[32+1]; //多一字节是为了保存'\0'结尾符
 string name;
 color clr;
};

car c;
car* pC=new car();
void print_car(car* pCar)
{
 if(car)
 {
  cout<<"ID:"<<pCar->id<<endl;
  cout<<"Name:"<<pCar->name<<endl;
  color* pColor=&pCar->clr;
  cout<<"Color Info(RGB)"<<pColor->red<<""<<pColor->green<<""<<pColor->blue<<endl;
 }
}
=========
// 类定义与使用
//
#i nclude "stdafx.h"
#i nclude "iostream"
#i nclude "string"
using namespace std;

struct color
{
 unsigned char red;
 unsigned char blue;
 unsigned char green;
};

class car
{
private:
 char id[32+1]; //多一字节是为了保存'\0'结尾符
 string name;
 color clr;
public:
 void print()
 {
  cout<<"ID:"<<id<<endl;
  cout<<"Name:"<<pCar->name<<endl;
  color* pColor=&pCar->clr;
  cout<<"Color Info(RGB)"<<pColor->red<<""<<pColor->green<<""<<pColor->blue<<endl;
 }
};

car c;
c.print();
car* pcar=&c;
pcar->print();
=========
// 类定义与使用
//
#i nclude "stdafx.h"
#i nclude "iostream"
#i nclude "string"
using namespace std;

struct color
{
 unsigned char red;
 unsigned char blue;
 unsigned char green;
};

class car
{
private:
 char id[32+1]; //多一字节是为了保存'\0'结尾符
 string name;
 color clr; //设color为私有
public:
 void print()
 {
  cout<<"ID:"<<name<<endl;
 }
 void getColor(color& ref_clr) //加两个特定的获取 修改函数
 {
  ref_clr=clr;
 }
 void setColor(color _clr)
 {
  clr=_clr;
 }
};
==========

 
 
发表评论:
载入中。。。

 
 
 

梦翔儿网站 梦飞翔的地方 http://www.dreamflier.net
中华人民共和国信息产业部TCP/IP系统 备案序号:辽ICP备09000550号

Powered by Oblog.