By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

static variable problem

P: n/a
Hi there,

I am little confused with the code below

using std::ofstream;

struct A {
static ofstream fout;

int main() {"a.dat");
return 0;

I think the code is ok. And certainly it compiles (g++ -c But
it fails when I wanted the executable (g++ -o afs and gives the
following error

In function 'main':
: undefined reference to 'Test::fout'
collect2: ld returned 1 exit status

I am really surprised with the happening. Please indicate what I am

Thank you.


Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
"Nasim" <na*********> wrote in message
using std::ofstream;

struct A {
static ofstream fout;

Don't forget to define A::fout. What you have above is just a declaration
of fout. Just add the following

ofstream A::fout;

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.