| 1 |
// { dg-do run } |
| 2 |
// GROUPS passed conversions |
| 3 |
// cvt file |
| 4 |
// Message-Id: <[email protected]> |
| 5 |
// From: [email protected] (Paul Stravers) |
| 6 |
// Subject: conversion method never called |
| 7 |
// Date: Thu, 7 Jan 93 18:08:33 +0100 |
| 8 |
|
| 9 |
#include <stdio.h> |
| 10 |
|
| 11 |
class test |
| 12 |
{ |
| 13 |
double d; |
| 14 |
int i; |
| 15 |
public: |
| 16 |
test(double dd,int ii) {d=dd; i=ii;} // constructor |
| 17 |
operator int&() {return i;} // define a conversion from test to int& |
| 18 |
int& geti() {return i;} // same thing, but different |
| 19 |
}; |
| 20 |
|
| 21 |
int main() |
| 22 |
{ |
| 23 |
test t(3.14, 5); // Create an object t of class "test" |
| 24 |
int x = (int&)t; // This should call operator int&() but it does not ... |
| 25 |
int y = t.geti(); // x and y should both be 5 ... |
| 26 |
if (x == 5 && y == 5) |
| 27 |
printf ("PASS\n"); |
| 28 |
else |
| 29 |
{ printf ("FAIL\n"); return 1; } |
| 30 |
} |