程序中的顺序

一个程序的建立是由main.cpp函数,_执行程序.cpp,__a执行程序.h。
假设买车的价格。
main.cpp格式

#include<iostream>
using namespace ::std;

#include"car.h" //执行程序的头文件

void foo(Car *pcar)
{
   pcar->print();
   pcar->stop();

}

int main()
{
 Car a;
 cout<<sizeof(a)<<endl;
 cout<<"The address of a is"<< &a <<endl;
 a.setProperty(10000,10001);
 a.run();
 foo(&a);
 return 0;
}

car.cpp的格式
程序主要的执行实现全都在这

#include<iostream>
using namespace ::std;

#include"car.h"//同样得有

   void Car::run()
{
cout << "car run"<<endl;
}

    void Car::stop()
{
 cout <<"car stop"<<endl;
}


   void Car::setProperty(int price, int carNum)
{
  this-> m_price=price;
  this-> m_carNum=carNum;
}
   void Car::print()
{
   cout<<"in "<<__func__<<" this= "<< this <<endl;
}

car.h的格式
其中要定义头文件同时还有说明使用到的函数

#ifndef _CAR_H_//必须写
#define _CAR_H_//必须写


class Car{
public:
    void run();
    void stop();
    
    void setProperty(int price, int carNum);
    void print();
private:
    int m_price;
    int m_carNum;
};



#endif//必须写

Robocup 2D中的函数体系就是这样而这个希望这个对以后自己写有帮助吧

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值