N
Nasim
Hi there,
I am little confused with the code below
//afs.cc
#include<fstream>
using std:fstream;
struct A {
static ofstream fout;
};
int main() {
A::fout.open("a.dat");
A::fout.close();
return 0;
}
I think the code is ok. And certainly it compiles (g++ -c afs.cc). But
it fails when I wanted the executable (g++ -o afs afs.cc) 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
missing.
Thank you.
Nasim
I am little confused with the code below
//afs.cc
#include<fstream>
using std:fstream;
struct A {
static ofstream fout;
};
int main() {
A::fout.open("a.dat");
A::fout.close();
return 0;
}
I think the code is ok. And certainly it compiles (g++ -c afs.cc). But
it fails when I wanted the executable (g++ -o afs afs.cc) 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
missing.
Thank you.
Nasim