C++ keeping a list of objects and calling a contructor through another function
- by Nona Urbiz
why isnt my object being created?
When I do it like so, I am told error C2065: 'AllReferrals' : undeclared identifier
as well as error C2228: left of '.push_back' must have class/struct/union.
If I put the list initialization before the class I get error C2065: 'AllReferrals' : undeclared identifier.
Thanks!
#include <iostream>
#include <fstream>
#include <regex>
#include <string>
#include <list>
#include <map>
using namespace std;
using namespace tr1;
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);
cout << AllReferrals.size();
cout << "\n why does that ^^ say 0 (help me make it say one)?";
cout << "\n and how can i AllReferrals.push_back(this) from my constructor?";
cout << " When I do it like so, I am told error C2065: 'AllReferrals' : undeclared identifier";
cout << " as well as error C2228: left of '.push_back' must have class/struct/union.";
cout << " If I put the list initialization before the class I get error C2065: 'AllReferrals' : undeclared identifier.";
cout << "\n\n\t Thanks!";
getchar();
}