🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2803

Re: new syntax for new operator

#2803
From: Alex Martelli
Date: Fri, 01 Dec 1995 19:14
50 lines
2295 bytes
dak <pierreba@poster.cae.ca> writes:
	...
>	A a4 = new (88,91) A; // auto A object with overloaded new.
	...
>As can be seen, the syntax does not break any existing code since it is
>currently illegal to assign the result of a new operation to the declared
>variable when the pointer types are not compatible (point 1). The syntax

This is not necessarily true.  If class A has a constructor accepting
an A* argument, or some other related cases (e.g., A publically derives
from B and has a constructor accepting a B* argument), and operator new
has an overloaded version (global or class-specific) accepting two extra
int arguments, then the expression you propose is not currently illegal.
It is not immediately clear whether the resulting ambiguity can be solved
in a totally satisfactory way.

Note that an A constructor taking a B* argument, with A publically
derived from B, is quite idiomatical in envelope/letter, aka 'handle',
idioms, a la:

class Foo_abstract {
public: virtual void Bar() const = 0;
        static Foo_abstract * DefaultFooFactory();
        // etc
};

class Foo_envelope: public Foo_abstract {
    Foo_abstract *letter;
public:
    Foo_envelope(Foo_abstract *p=0): letter(p) {
       if(!letter) letter=DefaultFooFactory();
    }
    virtual void Bar() const { letter->Bar(); }
    // etc
};


Alex
--
DISCLAIMER: these are MY personal opinions and viewpoints, NOT connected
in any way with my employer, nor any other organization or individual!
Email: martelli@cadlab.it -- Phone: +39 (51) 597 313  [Fax: 597 120]
Cad.Lab S.p.A., v. Ronzani 7/29, 40033 Casalecchio (BO), Italia


---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <DIwK3w.LKz@cadlab.it>
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt
References: <Pine.A32.3.91.951130114452.18134A-100000@zorglub.cae.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt
From: martelli@cadlab.it (Alex Martelli)
Newsgroups: comp.std.c++
Subject: Re: new syntax for new operator
Date: 01 Dec 1995 19:14:45 GMT
Organization: CAD.LAB S.p.A., Bologna, Italia
Approved: Matt@Austern
Message-ID: <DIwK3w.LKz@cadlab.it>
References: <Pine.A32.3.91.951130114452.18134A-100000@zorglub.cae.ca>
NNTP-Posting-Host: austern.hip.berkeley.edu