This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Not Const Temporaries


Hello,

I'm trying to compil the following file :
- it compils and work fine on my solaris :
pci>./test
before
TKeeped[00021E80]
TKeeper[EFFFF770](TKeeped[00021E80])::Init (1)
TKeeped[00021E80](0)::++
after
TKeeper[EFFFF770](TKeeped[00021E80])::Reset
TKeeped[00021E80](1)::--
~TKeeped[00021E80]
out of scope
total keeper created : 1
- it gives me an error on linux :
pci>g++ -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.0)
pci>g++ -o test
test.cc                                                         test.cc:
In function `TKeeper TKeeped::New ()':                                
test.cc:80: no matching function for call to `TKeeper::TKeeper 
(TKeeper)'
test.cc:13: candidates are: TKeeper::TKeeper (TKeeped &)
test.cc:16:                 TKeeper::TKeeper (TKeeper &)
test.cc: In function `int main ()':
test.cc:87: no matching function for call to `TKeeper::TKeeper 
(TKeeper)'
test.cc:13: candidates are: TKeeper::TKeeper (TKeeped &)
test.cc:16:                 TKeeper::TKeeper (TKeeper &)

Any hints/clue to make it work ?

// file test.cc
#include <stdio.h>

class TKeeped;
class TKeeper
{
  TKeeped &keeped;

  void Init(void);
  void Reset(void);
public:
  TKeeped &Keeped(void) { return keeped; }

  TKeeper(TKeeped &_keeped) : keeped(_keeped) { Init(); }
  ~TKeeper(void) { Reset(); }

  TKeeper(TKeeper &keeper) : keeped(keeper.Keeped()) { Init(); }

private:
  static int created;
public:
  static int Created(void) { return created; }
};

class TKeeped
{
  int count;
public:
  TKeeped(void);
  ~TKeeped(void);

  static TKeeper New(void);
private:
  friend TKeeper;
  void KeeperAdd(void);
  void KeeperRemove(void);
};

int TKeeper::created = 0;
void TKeeper::Init(void) 
{ 
  ++created;
  printf("TKeeper[%08X](TKeeped[%08X])::Init (%d)\n", 
         this, &Keeped(), created); 
  Keeped().KeeperAdd(); 
}

void TKeeper::Reset(void)
{
  printf("TKeeper[%08X](TKeeped[%08X])::Reset\n", this, &Keeped()); 
  Keeped().KeeperRemove();
}

TKeeped::TKeeped(void) : 
  count(0) 
{ 
  printf("TKeeped[%08X]\n", this); 
}

TKeeped::~TKeeped(void) 
{ 
  printf("~TKeeped[%08X]\n", this); 
}

void TKeeped::KeeperAdd(void) 
{ 
  printf("TKeeped[%08X](%d)::++\n", this, count);
  ++count; 
}

void TKeeped::KeeperRemove(void) 
{ 
  printf("TKeeped[%08X](%d)::--\n", this, count);
  if(--count) return;
  delete this;
}

TKeeper TKeeped::New(void)
{
  return TKeeper(* new TKeeped); 
}

int main(void)
{
  {
    printf("before\n");
    TKeeper keeper(TKeeped::New());
    printf("after\n");
  }
  printf("out of scope\n");
  printf("total keeper created : %d\n", TKeeper::Created());
}

-- 
                                   \|/      Philippe Cizaire
                                  (o o)       
 . ..  .. -  --  ----  ==  ===oOO==(_)==OOo===  ==  ----  --  - ..  .. .
  High speed, Plug And Play,                pci@silicomp.com
 WWW KoMpAtIbLe, Java++, FT,   .ooo0 0ooo.  Tel. +33 687 74 54 54  
 CORBA 5.9 Compliant and more  (   ) (   )  Fax. +33 476 41 66 67
   .  ..   ...  -  ---  ==  ====\ (===) /====  ==  ---  -  ...   ..  .
                                 \_) (_/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]