default parameter value for a reference from a constructor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, all,

I have following code:

class A { };

class B
{
 public:
    void foo( A& ra = A() ) { }
};

int main() {
   return 0;
}

If I compile with g++, it has following error message: invalid type 'A' for default argument to 'A&'.

But when I compile it using SunStudio compiler, it works.

I suspect the error is due to set the default value for reference "ra" with a constructor.

Can anyone explain whether the above code is valid in C++ standard ? If not, how to make it work by g++ ?

Thanks.

Michael


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux