저는 프로그래밍에 익숙하지 않고 일반적으로 헤더 파일에 혼란 스럽습니다. 나는 즉각적인 컴파일 문제에 도움을 청하고 나의 코드를 작성하기위한보다 깔끔하고 안전하며 매끄러운 방법에 대한 일반적인 제안을 고맙게 생각한다."헤더 파일의 '<'token"앞에 예상 된 이니셜 라이저
저는 현재 Simulation
클래스에 main()에 있던 많은 코드를 다시 패키지하고 있습니다. 이 클래스의 헤더 파일에서 컴파일 오류가 발생합니다. 나는 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,int,&Host::getAgeInY> >, // 1 - Age index
hashed_non_unique< tag<household>,const_mem_fun<Host,int,&Host::getHousehold> >, // 2 - Household index
ordered_non_unique< // 3 - Eligible by age & household
tag<aeh>,
composite_key<
Host,
const_mem_fun<Host,int,&Host::getAgeInY>,
const_mem_fun<Host,bool,&Host::isEligible>,
const_mem_fun<Host,int,&Host::getHousehold>
>
>,
ordered_non_unique< // 4 - Eligible by household (all single adults)
tag<eh>,
composite_key<
Host,
const_mem_fun<Host,bool,&Host::isEligible>,
const_mem_fun<Host,int,&Host::getHousehold>
>
>,
ordered_non_unique< // 5 - Household & age
tag<ah>,
composite_key<
Host,
const_mem_fun<Host,int,&Host::getHousehold>,
const_mem_fun<Host,int,&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 aj, 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을 인식하지 관련된 다른 오류의 무리를 얻을.
내가 이해할 수있는 모든 부스트 #includes가있는 것처럼 보입니다. 그 밖의 무엇이 잘못 될 수 있습니까?
즉각적인 제안, 문제 해결 정보 및 내 코드에 대한 기타 조언에 감사드립니다. 내 계획은 EventPQ 컨테이너에 대해 "Event.h"에서 수행하는 것과 비슷한 태그를 정의하는 typedef와 struct를 포함하는 "HostContainer.h"파일을 만드는 것입니다. 나는 이것이 합법적이고 좋은 형태라고 생각합니다.
typedef를 심각하게 고려해야합니다. 작은 조각을 typedef 한 다음 그것을 사용하여 빌드하십시오. –
당신이 어떻게 깨뜨릴 지 예를 들어 주시겠습니까? – Sarah
예. 내가 코멘트로 게시하기에는 너무 길기 때문에 답으로 게시했습니다. –