Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/C++/Front End/Language    [ Add a report in this area ]  
Report #:  51623   Status: Closed
error occurs when result of ?: binded to const reference
Project:  C++Builder Build #:  10.0.2166.28377
Version:    10.0 Submitted By:   Sergiy Kanilo
Report Type:  Basic functionality failure Date Reported:  9/5/2007 6:31:59 PM
Severity:    Commonly encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All versions Internal Tracking #:   255266
Resolution: Fixed (Resolution Comments) Resolved in Build: : 14.0.3483.23033
Duplicate of:  None
Voting and Rating
Overall Rating: (1 Total Rating)
5.00 out of 5
Total Votes: 10
Description
result of ? A() : A() has type A, which should bind to a A const&,
C++ compiler gives and error when A has explicitely declared constructor and destructor
Steps to Reproduce:
create a console application, type code

struct A
{
  A();
~A();
};

int main()
{
  A a( 1 ? A() : A() );
}

compilation returns

[C++ Error] Unit1.cpp(17): E2357 Reference initialized with 'A', needs lvalue of type 'A'
[C++ Error] Unit1.cpp(17): E2340 Type mismatch in parameter 1 (wanted 'const A &', got 'A')

note that the error disappeared when declatarion of either A's constructor or destructor is removed
Workarounds
None
Attachment
None
Comments

None

Server Response from: ETNACODE01