static std :: function <t>不完整类型

时间:2017-12-14 19:46:37

标签: c++

我正在尝试实现静态std :: function对象,我得到不完整类型错误。为什么我会收到这样的错误,语法对我来说很好看?

使用此代码可以重现错误。

    #include <string>
    #include <functional>
    int foobar(std::string){

    }
    class A{
    public:
        template<typename T>
        static std::function<T> foo //error is here;

        template<typename T>
        static void bar(T t){
            A::foo<T> = t;
        }
    };
    int main(){
        A::bar(foobar);
    }

虽然错误是:

user@user:~/Desktop$ g++ asd.cpp -std=c++17
asd.cpp: In instantiation of ‘static void A::bar(T) [with T = int (*)(std::__cxx11::basic_string<char>)]’:
asd.cpp:17:15:   required from here
asd.cpp:9:26: error: ‘A::foo<int (*)(std::__cxx11::basic_string<char>)>’ has incomplete type
  static std::function<T> foo;
                          ^~~
In file included from /usr/include/c++/7/functional:58:0,
                 from asd.cpp:2:
/usr/include/c++/7/bits/std_function.h:147:11: note: declaration of ‘class std::function<int (*)(std::__cxx11::basic_string<char>)>’
     class function;

操作系统:Ubuntu 17.10

海湾合作委员会:7.2

0 个答案:

没有答案