Hello,
I'd like manage a ofstream type "inside" a class but some problem occur...If I define outfile out the class, all is ok; if I declare and define it inside the class, this happen. Any hints please?
Code:static ofstream _outfile("howmany2.txt", fstream::out); class HowMany { static std::ofstream outfile; string _name; static int _objectCount; public: HowMany(const string& id = "") : _name(id) { outfile.open("howmany.txt", ios::out); _objectCount++; } static void print(const string& msg = "") { if (msg.size() != 0) _outfile << msg << ": "; _outfile << "objectCount = " << _objectCount << endl; outfile << "hello"; }Code:error LNK2001: unresolved external symbol "private: static class std::basic_ofstream<char,struct std::char_traits<char> > HowMany::outfile" (?outfile@HowMany@@0V?$basic_ofstream@DU?$char_traits@D@std@@@std@@A) howmany.obj : error LNK2001: unresolved external symbol "private: static class std::basic_ofstream<char,struct std::char_traits<char> > HowMany::outfile" (?outfile@HowMany@@0V?$basic_ofstream@DU?$char_traits@D@std@@@std@@A)


Reply With Quote


Bookmarks