|
|
|
|
|
|
| Author |
Message |
Siemel Naran *nix forums beginner
Joined: 26 Feb 2005
Posts: 35
|
Posted: Fri Feb 04, 2005 7:54 am Post subject:
Re: static variable problem
|
|
|
"Nasim" <nasim.haque@gmail.com> wrote in message
| Quote: | //afs.cc
#include<fstream
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; |
|
| Back to top |
|
 |
Nasim *nix forums beginner
Joined: 04 Feb 2005
Posts: 1
|
Posted: Fri Feb 04, 2005 7:04 am Post subject:
static variable problem
|
|
|
Hi there,
I am little confused with the code below
//afs.cc
#include<fstream>
using std::ofstream;
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 |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Thu Jan 08, 2009 7:53 pm | All times are GMT
|
|
Loans | Magazine Subscriptions | Links of Movies | Mobile Phones | Sprint Ringtones
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|