🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

standard conversions applied after user-defined conversions ???

#1957
From: Jeff Anton
Date: Tue, 12 Sep 1995 22:33
61 lines
2092 bytes
In the following code, it seems to me that over.best.ics should allow
the following call to func(...) however no compiler I've found supports this.
It's possible that dcl.init.ref is the section which disallows this,
but it's very hard to tell.  I know this could be abused or mislead
but it is also valuable and I can not find a good syntactic work around
other than explict construction of the argument.

The reason to do this is that I would like to have an abstract base
class which is passed to library routines, but I want the object that
supports that interface(abstract base class) to be implictly constructed
in the caller.  This way the library can be built with only the
abstract base class in scope and the calling module can 'own' the real
object implementation.

The standard conversion sequence should include base class conversion
and qualification adjustment, but it seems that the base class conversion
is not considered after a user-defined conversion.

Is this a bad approach?  Am I missing a viable way to do this?  Is this
a hole in the draft?


class A {
public:
    virtual ~A() {};
    virtual int f() = 0;
};

void func(const A &)
{
}


class B : public A
{
public:
    B(int);
    virtual ~B();
    virtual int f();
};

int
B::f()
{
    return 0;
}


int
main()
{
    func(2);
    return 0;
}

				Jeff Anton
				anton@illustra.com

[ 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: <9509122109.AA18138@grail.illustra.com>
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
From: anton@illustra.com (Jeff Anton)
Newsgroups: comp.std.c++
Subject: standard conversions applied after user-defined conversions ???
Date: 12 Sep 1995 22:33:04 GMT
Organization: ?
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <9509122109.AA18138@grail.illustra.com>
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
Content-Length: 1359
X-Lines: 57
Originator: clamage@taumet