Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ clang中指向函数指针的变量模板的未定义引用,但不是gcc #包括 静态constexpr bool isSSE2=true; 模板 静态空隙(*fp)(); 模板 静态void foo_c(){ std::cout_C++ - Fatal编程技术网

C++ clang中指向函数指针的变量模板的未定义引用,但不是gcc #包括 静态constexpr bool isSSE2=true; 模板 静态空隙(*fp)(); 模板 静态void foo_c(){ std::cout

C++ clang中指向函数指针的变量模板的未定义引用,但不是gcc #包括 静态constexpr bool isSSE2=true; 模板 静态空隙(*fp)(); 模板 静态void foo_c(){ std::cout,c++,C++,您必须首先初始化fp(): 模板 静态空隙(*fp)()=nullptr; 它在Clang 4.0中编译并运行良好:。 尽量总是初始化变量,这样可以避免各种麻烦。fp();是一个函数声明??在C++14中,这是一个格式不正确的;变量模板可能不会声明为静态的。但是最新的C++17草案已经改变了。C++17草案N4618说,如果静态变量模板在没有定义的情况下隐式实例化,这是一个格式不正确的NDR,但是我找不到任何地方说明模板是否ate static void(*fp)(;是否为定义 #includ

您必须首先初始化fp():

模板
静态空隙(*fp)()=nullptr;
它在Clang 4.0中编译并运行良好:。
尽量总是初始化变量,这样可以避免各种麻烦。

fp();
是一个函数声明??在C++14中,这是一个格式不正确的;变量模板可能不会声明为
静态的
。但是最新的C++17草案已经改变了。C++17草案N4618说,如果静态变量模板在没有定义的情况下隐式实例化,这是一个格式不正确的NDR,但是我找不到任何地方说明
模板是否ate static void(*fp)(;
是否为定义
#include <iostream>

static constexpr bool isSSE2 = true;

template<typename T>
static void (*fp)();

template<typename T>
static void foo_c() {
    std::cout << "foo_c get called." << std::endl;
}

template<typename T>
static void foo_sse2() {
    std::cout << "foo_sse2 get called." << std::endl;
}

int main() {
    if (isSSE2)
        fp<int> = foo_sse2<int>;
    else
        fp<int> = foo_c<int>;

    fp<int>();

    return 0;
}
$ clang++ "Source.cpp" -o "foo.exe" -std=c++14 -O2
Source.cpp:6:15: warning: variable 'fp<int>' has internal linkage but is not defined [-Wundefined-internal]
static void (*fp)();
              ^
Source.cpp:20:9: note: used here
        fp<int> = foo_sse2<int>;
        ^
1 warning generated.
C:\msys64\tmp\Source-6600e8.o:(.text+0x2a): undefined reference to `fp<int>'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
template<typename T>
static void (*fp)() = nullptr;