加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 头文件中“”标记之前的预期初始值设定项”

发布时间:2020-12-16 09:27:37 所属栏目:百科 来源:网络整理
导读:我对编程很新,并且通常会被头文件和包含内容搞糊涂了.我想帮助解决立即编译问题,并希望获得关于编写代码的更清晰,更安全,更光滑的方法的一般建议. 我目前正在将许多曾经在main()中的代码重新打包到Simulation类中.我在这个类的头文件中遇到编译错误.我正在使
我对编程很新,并且通常会被头文件和包含内容搞糊涂了.我想帮助解决立即编译问题,并希望获得关于编写代码的更清晰,更安全,更光滑的方法的一般建议.

我目前正在将许多曾经在main()中的代码重新打包到Simulation类中.我在这个类的头文件中遇到编译错误.我正在使用gcc 4.2.1版进行编译.

// Simulation.h
#ifndef SIMULATION_H
#define SIMULATION_H

#include <cstdlib>
#include <iostream>
#include <cmath>
#include <string>
#include <fstream>
#include <set>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/mem_fun.hpp>
#include <boost/multi_index/composite_key.hpp> 
#include <boost/shared_ptr.hpp>
#include <boost/tuple/tuple_comparison.hpp>
#include <boost/tuple/tuple_io.hpp>

#include "Parameters.h"
#include "Host.h"
#include "rng.h"
#include "Event.h"
#include "Rdraws.h"

typedef multi_index_container< // line 33 - first error
  boost::shared_ptr< Host >,indexed_by< 
    hashed_unique< const_mem_fun<Host,int,&Host::getID> >,// 0 - ID index
    ordered_non_unique< tag<age>,const_mem_fun<Host,&Host::getAgeInY> >,// 1 - Age index
    hashed_non_unique< tag<household>,&Host::getHousehold> >,// 2 - Household index
    ordered_non_unique< // 3 - Eligible by age & household
      tag<aeh>,composite_key<
    Host,&Host::getAgeInY>,bool,&Host::isEligible>,&Host::getHousehold>
    >
      >,ordered_non_unique< // 4 - Eligible by household (all single adults)
      tag<eh>,ordered_non_unique< // 5 - Household & age
      tag<ah>,&Host::getHousehold>,&Host::getAgeInY>
    >
       >
    > // end indexed_by
  > HostContainer; 

typedef std::set<int> HHSet;

class Simulation
{
  public:
  Simulation( int sid );
  ~Simulation();

  // MEMBER FUNCTION PROTOTYPES
  void runDemSim( void );
  void runEpidSim( void );
  void ageHost( int id );
  int calcPartnerAge( int a );
  void executeEvent( Event & te );
  void killHost( int id );
  void pairHost( int id );
  void partner2Hosts( int id1,int id2 );
  void fledgeHost( int id );
  void birthHost( int id );
  void calcSI( void );
  double beta_ij_h( int ai,int aj,int s );
  double beta_ij_nh( int ai,int s );

 private:
  // SIMULATION OBJECTS
  double t;
  double outputStrobe;
  int idCtr;
  int hholdCtr;
  int simID;
  RNG rgen;
  HostContainer allHosts; // shared_ptr to Hosts - line 102 - second error
  HHSet allHouseholds; 
  int numInfecteds[ INIT_NUM_AGE_CATS ][ INIT_NUM_STYPES ]; 
  EventPQ currentEvents; 

  // STREAM MANAGEMENT
  void writeOutput();
  void initOutput();
  void cloSEOutput();

  std::ofstream ageDistStream;
  std::ofstream ageDistTStream;
  std::ofstream hhDistStream;
  std::ofstream hhDistTStream;

  std::string ageDistFile;
  std::string ageDistTFile;
  std::string hhDistFile; 
  std::string hhDistTFile;
};

#endif

我希望其他文件与这个问题不太相关.当我编译时

g++ -g -o -c a.out -I /Applications/boost_1_42_0/ Host.cpp Simulation.cpp rng.cpp main.cpp Rdraws.cpp

我明白了

Simulation.h:33: error: expected initializer before '<' token
Simulation.h:102: error: 'HostContainer' does not name a type

然后是一堆与无法识别HostContainer相关的其他错误.

看起来我对HostContainer的所有正确的Boost #includes都有所了解.还有什么可能出错?

我将非常感谢有关我的代码的即时建议,疑难解答提示和其他建议.我的计划是创建一个“HostContainer.h”文件,其中包含定义其标记的typedef和结构,类似于我在EventPQ容器的“Event.h”中所做的.我认为这是合法的,良好的形式.

解决方法

multi_index_container似乎在名称空间提升中.所以你必须使用boost :: multi_index_container显式引用它,或者使用声明/指令.

HostContainer错误是由第一个错误引起的.通常,您应该按顺序解决C编译错误.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读