I have an example code below.
#include<iostream> template<typename T> class XYZ { private: T & ref; public: XYZ(T & arg):ref(arg) { } }; class temp { int x; public: temp():x(34) { } }; template<typename T> void fun(T & arg) { } int main() { XYZ<temp> abc(temp()); fun(temp()); //This is a compilation error in gcc while the above code is perfectly valid. }
In the above code, although the XYZ constructor accepts the argument as a non-const reference, it compiles fine and the fun function does not compile. Is this specific to the g ++ compiler or the C ++ standard, have something to say about this?
Edit:
g ++ -v gives this.
gcc version 4.5.2 (Ubuntu / Linaro 4.5.2-8ubuntu4)
chappar
source share