2012-09-09 58 views
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); 
+0

一些代码将是一个良好的开端。 – chris

+0

好吧,它就像600线左右,我可以张贴标题,虽然我猜.. – user1647959

+1

做一个较小的例子与一个功能,没有别的。最好的事情是显示错误的最小可编译样本。 – chris

回答

3

确定。遵循这些规则,你应该用的东西相当接近结束:

  1. 认沽类,类型定义,#define语句,模板和内联函数在头文件
  2. 缠上的#ifndef头文件/#定义/# 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 ... } 
+0

那么,你肯定会遇到问题:没有函数声明。我即将发布这一小部分,但这不仅仅是那些新来的分班人员的问题。 – chris

+0

welp。那会做到这一点哈哈。谢谢你们。对于我的糟糕准备感到抱歉 – user1647959

相关问题