Separating a Class into .h and .cxx Files

When I implement a class in C++, I break it into two files:

  1. The header file (such as rocket.h)
    1. This file contains all the comments that a programmer needs to use myclass. This documents only the public members of the class.It also contains the class declaration, beginning with thekeyword class and ending with the final closed bracketand semicolon. All of this is wrapped in a macro guard, so the totalmight look like this:
      // File: rocket.h
      // Written by Michael Main (main@colorado.edu), Dec 18, 2009
      // Comments on each public member ...
      #ifndef ROCKET_H
      #define ROCKET_H
      namespace colorado_edu
      {
          class rocket
          {
          ...
          };
      #endif
      

  2. The implementation file (such as rocket.cxx)
    1. This contains the implementations of all the class's memberfunctions. Also, at the top, I provide a comment that is a classinvariant. This comment describes how the member variables representan object. In effect, the class invariant is an implicit preconditionfor every member function (except the constructors) and it is animplicit postcondition of every member function (except thedestructor).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值