From 8702252255342580599
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,6d43dabd81d37c8e,start
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2003-01-23 09:49:12 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!colt.net!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: danielgutson@hotmail.com (danielgutson@hotmail.com)
Newsgroups: comp.std.c++
Subject: suggestions: about constructors and destructors
Date: Thu, 23 Jan 2003 17:49:07 +0000 (UTC)
Organization: http://groups.google.com/
Lines: 116
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <23478c42.0301230926.39a6959c@posting.google.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: mail2news.demon.co.uk 1043344147 21812 10.0.0.1 (23 Jan 2003 17:49:07 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Thu, 23 Jan 2003 17:49:07 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.05)
	id 18blTN-0005ff-00
	for mail2news@news.news.demon.net; Thu, 23 Jan 2003 17:49:06 +0000
X-Received: by mulga.cs.mu.OZ.AU
	id EAA16594; Fri, 24 Jan 2003 04:49:02 +1100 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ncar.ucar.edu
X-Newsgroups: comp.std.c++
X-NNTP-Posting-Date: 23 Jan 2003 17:26:44 GMT
X-Spam-Status: No, hits=-1.7 required=5.0
	tests=FORGED_HOTMAIL_RCVD,NOSPAM_INC,SPAM_PHRASE_00_01
	version=2.41
Xref: archiver1.google.com comp.std.c++:17447

Newgroupers:
 Please let me know comments about the following issues.

- overloading non-default destructors and destruction lists.

  * consecuences:
      1) when defined, non-default destr. hides the default
destructor, unless it is explicited (in the same sense the non-default
constructor does)
      2) non-default destructor only calleable through delete operator
and/or destruction list (for contained classes)
  * example1:

     struct Contained
     {
         ~Contained(int);
     };

     struct Container
     {
        Contained c;

        ~Container()
             : ~c(1)    //only way
        {}
     };

  * example2:
     struct S { ~S(int); };
     
     void f(void)
     {
          S s;    // invalid: no default destructor available
          S* p = new S;
          delete p(1);   //ok
     }

- 'const' constructor/destructor overloading:
     -> Provide the differentiation between constructing/destruction a
const and non const objects, using the 'const' keyword as a prefix of
the constructor declaration
   example:
     struct C
     {
        const C() { ... };
        C() { ... };
     };

     void f()
     {
          const C c1;  //invokes C::const C();
          C c2;        // invokes C::C()
     }

    Following proposal above (about destructor), same thing should be
available for destructors: (redefining the class)

     struct C
     {
        const C() { ... };
        C() { ... };

       ~C();
       const ~C();
     };

    -> proposed rules:
            * When constructing a const object, if there is no 'const
constructor' available, the non-const is used
            * When destructing a const object, if a const constructor
was provided, then a const destructor should also be provided

- non-default constructors for arrays:
    I'm talking about
        struct A
        { A(int); };

        void f(void)
        {
           A a[10](1);
           A b[10][20](2);
        }

    Same applicable through the new operator (I'm not talking about
overloading the 'new').

    Suggestion: a keyword for sending the 'index value' in a parameter
of the constructor. Let's sat constr_index<int Dim>, where Dim denotes
the dimension number. Dim should be a constant expression.
Example using struct A (defined above)

   void g(void)
   {
      A a[10](constr_index<0>);
      A b[10][20](constr_index<0>+constr_index<1>);
   }

   will construct: 
     a: an array of 10 A's, receiving the consecuent index number in
the constructor.
     b: a 10x20 matrix, accepting the sum of the row and the column in
the constructor.


I'd like to listen to your feedbacks,

thanks!

  Daniel.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



