From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25765 invoked by alias); 25 Jun 2002 17:04:31 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 25752 invoked from network); 25 Jun 2002 17:04:30 -0000 Received: from unknown (HELO mail.centropolisfx.com) (64.70.30.98) by sources.redhat.com with SMTP; 25 Jun 2002 17:04:30 -0000 Received: from centropolisfx.com (jupiter.centropolisfx.com [172.20.2.83]) by mail.centropolisfx.com (8.11.3/8.11.3) with ESMTP id g5PH8Hv725037; Tue, 25 Jun 2002 10:08:17 -0700 (PDT) Message-ID: <3D18A381.AEB823CB@centropolisfx.com> Date: Tue, 25 Jun 2002 10:04:00 -0000 From: Gokhan Kisacikoglu Reply-To: kisa@centropolisfx.com Organization: Centropolis Effects, LLC X-Accept-Language: en MIME-Version: 1.0 To: Brad Douglas CC: gcc-help@gcc.gnu.org Subject: Re: problems with undefined references References: <7DA8A54A920E1441960C129BDDFE4E9A042390@dr-honeydew.saabsystems.com.au> Content-Type: multipart/mixed; boundary="------------FFD5FC00A930243001F6714E" X-SW-Source: 2002-06/txt/msg00215.txt.bz2 This is a multi-part message in MIME format. --------------FFD5FC00A930243001F6714E Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-length: 165 Here I fixed your source code and attached it. You did not declare the static variable anywhere, it is also safer to call the static variable with its scope. Gokhan --------------FFD5FC00A930243001F6714E Content-Type: text/plain; charset=us-ascii; name="Singleton.cpp" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="Singleton.cpp" Content-length: 1470 #include "Singleton.h" //========================================================================= // Singleton class implementation // only the default constructor is implemented as it is the only constructor // that will be used so we will not get "undefined references" for the copy // constructor and assignment operator when linking // SingletonDestroyer Singleton :: destroyer; //------------------------------------------------------------------------- // initialize the pointer to the single isntance Singleton* Singleton::instance = 0; //------------------------------------------------------------------------- // default constructor (just initialises imlp) Singleton::Singleton() { } //------------------------------------------------------------------------- // getInstance: // if NULL construct the sinle instance, otherwise just return it Singleton* Singleton::getInstance() { // is it the first call? if (instance == 0) { // create sole instance instance = new Singleton; Singleton :: destroyer.setSingleton(instance); } // return the address of sole instance return instance; } Singleton::~Singleton() { } //========================================================================= // SingletonDestroyer class implementation SingletonDestroyer::~SingletonDestroyer() { delete instance; } void SingletonDestroyer::setSingleton( SingletonPtr _instance) { instance = _instance; } --------------FFD5FC00A930243001F6714E--