Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 781481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:14:11+00:00 2026-05-14T20:14:11+00:00

I’m pretty new to programming and am generally confused by header files and includes.

  • 0

I’m pretty new to programming and am generally confused by header files and includes. I would like help with an immediate compile problem and would appreciate general suggestions about cleaner, safer, slicker ways to write my code.

I’m currently repackaging a lot of code that used to be in main() into a Simulation class. I’m getting a compile error with the header file for this class. I’m compiling with gcc version 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

I’m hoping the other files aren’t so relevant to this problem. When I compile with

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

I get

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

and then a bunch of other errors related to not recognizing the HostContainer.

It seems like I have all the right Boost #includes for the HostContainer to be understood. What else could be going wrong?

I would appreciate immediate suggestions, troubleshooting tips, and other advice about my code. My plan is to create a “HostContainer.h” file that includes the typedef and structs that define its tags, similar to what I’m doing in “Event.h” for the EventPQ container. I’m assuming this is legal and good form.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T20:14:11+00:00Added an answer on May 14, 2026 at 8:14 pm

    The multi_index_container seems to be in namespace boost. So you have to refer to it either explicitly with boost::multi_index_container, or use using declarations/directives.

    The HostContainer error is caused by the first error. Usually you should address C++ compilation errors in order.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.