OSDN Git Service

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