[ MilošV @ 22.12.2003. 20:28 ] @
Prenosim sa borland.public.cppbuilder.language foruma...
Nista mi nije jasno :(
Citat:

Hi all, I just wanted to get people's thoughts on a compile error I'm
seeing with C++Builder6. I've been working with the libraries in the
Crystal Space open source project (http://crystal.sourceforge.net).

Here's the context the error appears in, and the specific error is
'Destructor name must match class name'.

Code:

template <class T>
class csArrayElementHandler
{
public:
static void Construct (T* address, T const& src)
{
new (static_cast<void*>(address)) T(src);
}

static void Destroy (T* address)
{
address->T::~T(); [blue]// <-- Here's where the error occurs[/blue]
}

static void InitRegion (T* address, int count)
{
for (int i = 0 ; i < count ; i++)
Construct (address + i, T ());
}
};



This code is in /include/csutil/array.h in case you're tempted
to peruse the cvs repository. I have it on pretty good authority
(one of the Crystal Space authors) that this code compiles just
fine on every other modern compiler he knows of, but Builder
won't compile it.

Da li tip zna nešto za što ja nisam čuo ili mu treba poslati Leku da mu
objasni par stvari o životu? :)
Ili oboje? :)
[ MilošV @ 22.12.2003. 20:34 ] @
OK, iskompajlira se kad se ukloni :: operator iz linije koja mu izaziva grešku ali...
Da li se klasa mogla malo klasičnije definisati?
[ Dragi Tata @ 23.12.2003. 20:22 ] @
Na prvi pogled, kod koji si postovao je neka vrsta zamene za std::allocator. Šta ti nije jasno u vezi sa tim?
[ MilošV @ 24.12.2003. 07:13 ] @
Cao :)
Kad malo iščitam, postaje mi jasnije... :) Takođe mi postaje još jasnije da nije trebalo preskakati poglavlje o templejtima (posljednje u "Thinking in C++") :) Da nije bilo ovoga...

U početku me zbunilo kad sam vidio da se žali na upozorenje 'Destructor name must match class name' a pritom u klasi ima funkcije koje se zovu Construct i Destroy... Sad već kontam (donekle :)

Evo cijelog koda sa čovjekovog novijeg posta na b.p.c.language:
Code:

Anybody have any clue why this program won't compile?
I get the error 'Destructor name must match class name'.
Is this a bug in the compiler?

//------- Header

template <class T>
class csArrayElementHandler {
public:
  static void Construct (T* address, T const& src)  {
    new (static_cast<void*>(address)) T(src);
  }
  static void Destroy (T* address)  {
    address->T::~T(); // <-- Here's where the error occurs
  }
};

template <class T, class ElementHandler = csArrayElementHandler<T> >
class csArray {
private:
  T* root;
public:
  csArray() {}

  ~csArray() {
    DeleteAll ();
  }

  void DeleteAll ()  {
    if (root)  {
      int i;
      for (i = 0 ; i < 10 ; i++)
        ElementHandler::Destroy (root + i);
      free (root);
      root = 0;
    }
  }
};

struct csHashElement {
  int key;
};

class TForm1 : public TForm {
__published:    // IDE-managed Components
private:    // User declarations
public:        // User declarations
        __fastcall TForm1(TComponent* Owner);
  csArray<csHashElement> ary;
};
//------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//------------------------------------------------------


//------- source file is empty