niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » C++
static variable problem
Post new topic   Reply to topic Page 1 of 1 [2 Posts] View previous topic :: View next topic
Author Message
Siemel Naran
*nix forums beginner


Joined: 26 Feb 2005
Posts: 35

PostPosted: Fri Feb 04, 2005 7:54 am    Post subject: Re: static variable problem Reply with quote

"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

PostPosted: Fri Feb 04, 2005 7:04 am    Post subject: static variable problem Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [2 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 7:53 pm | All times are GMT
navigation Forum index » Programming » C++
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Postfix + MySQL error: very strange variable %s iWarior Postfix 0 Mon Aug 25, 2008 2:01 pm
No new posts Unknown in header problem -SOLVED- Light Speed Postfix 0 Thu Jul 03, 2008 10:40 am
No new posts problem with sending mail nuxia Postfix 0 Mon Apr 21, 2008 3:58 am
No new posts Postfix 2.3.8 Virtual problem Blotto Postfix 0 Fri Apr 04, 2008 6:11 am
No new posts Postfix sending problem for local domain remote email monkey_magix Postfix 0 Mon Sep 10, 2007 10:17 am

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
[ Time: 0.3209s ][ Queries: 20 (0.2429s) ][ GZIP on - Debug on ]