为什么我的对象没有被创建?
我怎样才能AllReferrals.push_back(this);
从我的构造函数执行?
当我这样做时,我被告知
错误 C2065:“AllReferrals”:未声明的标识符
也
错误 C2228:“.push_back”左侧必须有类/结构/联合
如果我将列表初始化放在我得到的类之前
错误 C2065:“AllReferrals”:未声明的标识符
这是我的代码:
class Referral
{
public:
string url;
map<string, int> keywords;
static bool submit(string url, string keyword, int occurrences)
{
//if(lots of things i'll later add){
Referral(url, keyword, occurrences);
return true;
//}
//else
// return false;
}
private:
list<string> urls;
Referral(string url, string keyword, int occurrences)
{
url = url;
keywords[keyword] = occurrences;
AllReferrals.push_back(this);
}
};
static list<Referral> AllReferrals;
int main()
{
Referral::submit("url", "keyword", 1);
}