0

作成しているC++プログラムを複数のファイルに分割しました。

現在、すべてのメンバー関数宣言でこのエラーが発生しています。

私は何が間違っているのですか?

 3 class Office{
  4     private:
  5         static const int IDLE = 0, BUSY = 1;
  6         const int num_tellers;
  7         int students_served;
  8 
  9         vector<double> que;                                                   // a vector que which holds the arrival times of students entering an Office
 10         vector<int> tellers;                                                 // a vector to hold the status (IDLE or BUSY) of the tellers                *** INITIALIZED TO SIZE tellers[num_tellers] IN CONSTRUCTOR ***
 11 
 12 
 13         variate_generator<mt19937, exponential_distribution<> > serve_time;  // random variable, determines the time it takes a teller to serve a student
 14 
 15     public:
 16 
 17         Office(double const office_mean, int const num_tellers) : num_tellers(num_tellers), tellers(vector<int>(num_tellers, IDLE)),
 18                                                                   serve_time(variate_generator< mt19937, exponential_distribution<> >( mt19937(time(0)), exponential_distribution<>( 1 / office_mean))){
 19         }                                                // initialize tellers vector to size num_tellers w/ tellers[i] = IDLE, accumulated times to , and initializes serve_time random variable




 37 int Office::departure_destination(Event* departure) {     // returns the next destination of a student departing from an Office
 38 
 39     if (departure->depart_from == AID) {
 40         return determine_destination(.15, .15, 0, 0, .70);
 41     else if (departure->depart_from == PARKING)
 42         return next_destination = determine_destination(.3, 0, 0, 0, .7);
 43     else if (departure->depart_from == REGISTRAR)
 44         return next_destination = determine_destination(.25, 0, .1, 0, .65);
 45     else if (departure->depart_from == BURSAR)
 46         return next_destination = determine_destination(0, .1, .2, .1, .60);
 47     else
 48         return -1;
 49 }
 50 

次にヘッダーファイルで

 57 int Office::departure_destination(Event* departure);
4

1 に答える 1

3

わかった。これらのルールに従うと、かなり近いものになってしまうはずです。

  1. クラス、typedef、#defines、テンプレート、およびインライン関数をヘッダーファイルに配置します
  2. ヘッダーファイルを#ifndef /#define /#endifでラップして、誤って複数のインクルードが複数の定義済みシンボルを引き起こさないようにします
  3. 実装をc++ファイルに入れ、(1)を持つこのヘッダーを含めます。

これを理解する最も簡単な方法は、ヘッダーファイルには実際のマシン命令またはデータを生成するものがないことを理解することです。ヘッダー内のすべてが宣言型です。たとえば、変数を宣言するために使用された場合に、コードまたはデータがどのように生成されるかを説明します。C ++ファイルには、別のファイルで関数を呼び出したり、オブジェクトのメソッドを呼び出したりするときに必要なものを理解するために、これらの「アウトライン」が必要です。

#defineの種類の命令はすべてテキスト処理です。

テンプレートは実際にはチューリング完全な言語ですが、テンプレートを使用して何かを作成するまでコードを生成しません...そして、テンプレートは独自のC++ファイルを生成しているようなものです。

クラス宣言は、オブジェクトを作成することを選択した場合に、オブジェクトに含まれるものを定義します。

したがって、一般的なヘッダーファイル(my_headerなど)は次のようになります。

#ifndef MY_HEADER
#define MY_HEADER

extern int global;

class A {
   ... data declarations, inline functions ...
   public:
      void f();
};

#endif

およびC++ファイル:

#include "my_header"

int global; // only in ONE C file...this  generates real data

void A::f() { ... generates real code to be linked to ... }
于 2012-09-09T02:42:50.807 に答える