c++ generic struct

aclark17 (16)
Why wont this compile

template <class t>
struct a
{
a(t& ty=t() ,a* p=0):o(ty),n(p){}
t& o;
a* n;


};
firedraco (5414)
What are the errors?
Vlykarye (227)
Correction: It WILL compile.
If it doesn't compile for you, then you must be getting errors somewhere, and I doubt it is with this piece of code (unless your compiler is out of date).
Peter87 (3691)
A temporary object can't bind to a non-const reference.
Last edited on
Vlykarye (227)
It works in Visual Studio.
cire (1851)
It works in Visual Studio.


If your definition of "works" is "the compiler doesn't complain if I don't instantiate an instance," then yes, it "works."

1
2
3
4
5
6
7
8
9
10
11
12
template <class t>
struct a
{
a(t& ty=t() ,a* p=0):o(ty),n(p){}
t& o;
a* n;
}; 

int main()
{
    a<int> c ;
}


Registered users can post here. Sign in or register to post.