【发布时间】:2012-06-10 08:48:22
【问题描述】:
我有声明(或类似的)
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;
}
【问题讨论】:
-
你的类在你使用
map之前声明了吗? -
在使用
map之前是否声明了std::string? -
Pubby 是的,我包含了它的 h 文件和它的独立工作。 Robᵩ 是的,包括字符串。如果其中任何一个都不正确,那么它肯定不会编译 LucTouraille 现在查看您的 SSCCE 链接,稍后再发布
-
嗯,即使我添加了
Stock定义,代码也能完美编译(参见here)。你确定错误在这里吗?您可以尝试创建一个新项目并编译我链接的代码吗?
标签: c++ templates map eclipse-cdt