6

I have the declaration (or similar)

std::map< std::string, Stock*> &stocks;

throughout my code. Eclipse does not like this and produces a "Invalid template arguments" error.

Stock is declared as:

class Stock {

 public:
    Stock(std::string, qbbo::Financial_status_indicator, qbbo::Security_class,
          qbbo::Current_trading_state,
          qbbo::Market_category, qbbo::Reg_sho_action);
    ~Stock();
    void setFinancialStatusIndicator(qbbo::Financial_status_indicator financialStatusIndicator);
    void setSecurityClass(qbbo::Security_class securityClass);
    void setCurrentTradingState(qbbo::Current_trading_state tradingState);
    void setMarketCategory(qbbo::Market_category marketCategory);
    void setREGShoAction(qbbo::Reg_sho_action regSHOAction);
    bool isStockTrading();

  private:
    enum StockState {
      STOCK_STATE_OK, STOCK_STATE_UNKNOWN, STOCK_STATE_UNEXPECTED_CHARACTERISTIC
    };

    std::string name;
    int inventory;
    StockState currentState;

    // Expected values initialised in constructor
    qbbo::Financial_status_indicator expectedFinancialStatusIndicator;
    qbbo::Security_class expectedSecurityClass;
    qbbo::Current_trading_state expectedCurrentTradingState;
    qbbo::Market_category expectedMarketCategory;
    qbbo::Reg_sho_action expectedRegSHOAction;

    // Actual values as set by messages
    qbbo::Financial_status_indicator financialStatusIndicator;
    qbbo::Security_class securityClass;
    qbbo::Current_trading_state currentTradingState;
    qbbo::Market_category marketCategory;
    qbbo::Reg_sho_action regSHOAction;

    void nextState();
};

I cannot see whats invalid about this declaration and it compiles fine. Is there something I'm missing and Eclipse is catching?

Short Self Contained Correct Example

#include <string>
#include <map>

#include "stock.h"

int main() {
  std::map<std::string, Stock*> stocks;
}
ks1322
  • 33,961
  • 14
  • 109
  • 164
Jonathan Evans
  • 974
  • 2
  • 8
  • 18
  • Is your class declared before you use `map`? – Pubby Jun 06 '12 at 10:36
  • As long as you correctly initialize your reference, there is nothing wrong with your code AFAICT. I did not look at the code of `Stock`, as it is probably irrelevant: since your are storing pointers, even a simple forward declaration is sufficient (see [here](http://ideone.com/Vzg2w)). You will have to provide more information, ideally an [SSCCE](http://homepage1.nifty.com/algafield/sscce.html). – Luc Touraille Jun 06 '12 at 11:34
  • Is `std::string` declared before you use `map`? – Robᵩ Jun 06 '12 at 11:35
  • Pubby Yes, I include its h file and its working fine stand alone. Robᵩ Yup, string is included. If either of these wasn't true, surely it wouldn't compile LucTouraille Looking at your SSCCE link now and ill post it later – Jonathan Evans Jun 06 '12 at 11:40
  • 1
    Hmm, even if I add the `Stock` definition, the code compiles perfectly (see [here](http://ideone.com/pxnG7)). Are you sure the error is here? Could you try creating a new project and compiling the code I linked? – Luc Touraille Jun 06 '12 at 11:54

1 Answers1

2

Turned out to be an eclipse error. Creating a new project and re-following the steps Eclipse CDT C++11/C++0x support sorted it.

Community
  • 1
  • 1
Jonathan Evans
  • 974
  • 2
  • 8
  • 18