2012-06-06 42 views
6

我有声明(或类似)无效的模板参数<的std :: string,股票*>&个股

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

在我的代码。 Eclipse不喜欢这个,并产生一个“无效的模板参数”错误。

股票被声明为:

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(); 
}; 

我不能看到什么关于这个声明无效,它编译罚款。有什么我错过了,并且Eclipse在捕捉?

短自给式正确的示例

#include <string> 
#include <map> 

#include "stock.h" 

int main() { 
    std::map<std::string, Stock*> stocks; 
} 
+0

是您的类中声明你使用'map'过吗? – Pubby

+0

只要你正确地初始化你的引用,你的代码AFAICT没有任何问题。我没有看Stock'的'代码,因为它可能是无关紧要的:因为你的存储指针,甚至一个简单的向前声明就足够了(见[这里](http://ideone.com/Vzg2w))。您必须提供更多信息,理想情况下是[SSCCE](http://homepage1.nifty.com/algafield/sscce.html)。 –

+0

在使用map之前是否声明了'std :: string'? –

回答