Template Return Type with Default Value

前端 未结 6 1550
情歌与酒
情歌与酒 2021-02-10 20:46

So in writing a C++ template class, I have defined a method that returns an object of the templated type, as such:

template 
class Foo
{
public         


        
6条回答
  •  礼貌的吻别
    2021-02-10 21:41

    Do you really want to return an un-initialized value from this function? Sounds like it could lead to a whole lot of crap later down the line.

    Why don't you use an appropriate wrapper - if you have access to boost, consider boost::optional. This way, if you don't initialize it, it can be tested properly.

提交回复
热议问题