繁体   English   中英

使用std :: tuple_size时导致`error:incomplete type`

[英]Resulting in an `error: incomplete type` while using std::tuple_size

我在命名空间中有一个类模板
我在该命名空间内有一个非成员函数,它返回std::tuplestd::shared_ptr(s)<myown::myclass<Type>>
我调用函数F()并将其结果( std::tuple )传递给另一个非成员函数(在myown名称空间内)

namespace myown {

    template<typename T> class myclass{ /*...*/};

    template<>           class myclass<void>{ /*...*/};

    auto F()
    {
        return std::make_tuple(std::shared_ptr<myclass<int>>(),
                               std::shared_ptr<myclass<const char *>>(),
                               std::shared_ptr<myclass<int>>());
    }

    template <typename tup>
    auto anotherF(tup&& result){
        size_t s = std::tuple_size<tup>::value;//
        /*...*/
    }
}

 int main()
 {
     auto tr = myown::F();
     myown::anotherF(tr);
 }

使用std::tuple_size<tup>导致error: incomplete type...used in nested name specifier

您需要衰减类型以删除引用:

size_t s = std::tuple_size<std::decay_t<tup>>::value;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM