Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Kakav je ovo stil programiranja?

[es] :: C/C++ programiranje :: Kakav je ovo stil programiranja?

[ Pregleda: 2447 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

MilošV
Podgorica

Član broj: 7996
Poruke: 484
195.66.163.*



+1 Profil

icon Kakav je ovo stil programiranja?22.12.2003. u 20:28 - pre 247 meseci
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? :)
 
Odgovor na temu

MilošV
Podgorica

Član broj: 7996
Poruke: 484
195.66.163.*



+1 Profil

icon Re: Kakav je ovo stil programiranja?22.12.2003. u 20:34 - pre 247 meseci
OK, iskompajlira se kad se ukloni :: operator iz linije koja mu izaziva grešku ali...
Da li se klasa mogla malo klasičnije definisati?
 
Odgovor na temu

Dragi Tata
Malo ispod Kanade

Član broj: 1958
Poruke: 3906
199.171.112.*



+6 Profil

icon Re: Kakav je ovo stil programiranja?23.12.2003. u 20:22 - pre 247 meseci
Na prvi pogled, kod koji si postovao je neka vrsta zamene za std::allocator. Šta ti nije jasno u vezi sa tim?
 
Odgovor na temu

MilošV
Podgorica

Član broj: 7996
Poruke: 484
195.66.163.*



+1 Profil

icon Re: Kakav je ovo stil programiranja?24.12.2003. u 07:13 - pre 247 meseci
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

 
Odgovor na temu

[es] :: C/C++ programiranje :: Kakav je ovo stil programiranja?

[ Pregleda: 2447 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.