【发布时间】:2026-02-09 02:15:01
【问题描述】:
我正在尝试编译一些开源代码 (https://github.com/BieremaBoyzProgramming/bbpPairings),我可以使用 g++ (v6.3.0) 在 linux 上编译这些代码,但无法在 Visual Studio (VS Community 2019) 中编译/16.1.5),有点晦涩(对我来说,但我的 C++ 确实很弱)错误:“错误 C2143:语法错误:缺少';'在'
源代码中的违规代码是here,但从代码中提取的一个最小示例是:
#include <iostream>
#include <random>
class Configuration {};
class MatchesConfiguration {
public:
template <class RandomEngine>
MatchesConfiguration(
Configuration&&,
RandomEngine&);
};
template <class RandomEngine>
MatchesConfiguration::MatchesConfiguration(
Configuration&& configuration,
RandomEngine& randomEngine) {}
template
MatchesConfiguration::MatchesConfiguration<std::minstd_rand>( // <--- SYNTAX ERROR HERE
Configuration&&,
std::minstd_rand&);
int main()
{
std::cout << "Hello World!\n";
}
我查看了MSDN description of the error code,但我对 C++ 和模板的掌握太薄弱,无法弄清楚出了什么问题。项目 README 说 C++14 是预期的(对于 FS 的东西有一些可选的 C++17 东西,我认为在这里不重要),但据我所知,feature compatibility chart all of C+ VS 2019 应该支持 +14。
【问题讨论】:
-
我无法编译on Coliru,它使用g++ 8.2.0。
-
我对较新版本的 MSVC++ 没有那么丰富的经验,但这听起来像是应用程序中的兼容性设置。我认为,默认情况下,g++ v6.3.0 可能会编译期望 C++ 语言的旧版本。 g++ 6.5 是在去年 10 月根据gcc.gnu.org 发布的,所以我预计 6.3.0 会明显更早。您可能需要在 MSVC++ 中设置兼容性以符合旧版本的语言。
-
你想要这个godbolt.org/z/hpj4dK吗?
-
是否允许这种孤独的
template事情?不应该是template<>吗? -
@EtiennedeMartel No.
template<>用于显式特化,但此代码正在执行显式实例化
标签: c++ visual-c++ c++14