gpt4 book ai didi

c++ - Microsoft C++ 优化编译器已停止工作

转载 作者:行者123 更新时间:2023-11-30 01:16:12 24 4
gpt4 key购买 nike

我试图在一个类中定义一个模板成员函数,但每次我尝试构建这段代码时 MSVC 都会崩溃。我不确定这是否是 Visual Studio 2008 中的错误。这是一个最小的示例。

testTemp.h头文件:

#pragma once
#include <vector>
#include <iostream>
class testTemp
{
public:
testTemp(void);
~testTemp(void);
template<typename T>
std::vector<T> m_vMonitorVec;
int MonitorSignal(T x, std::vector<T> vec, int len);
};

这里是testTemp.cpp:

  #include "StdAfx.h"
#include "testTemp.h"

testTemp::testTemp(void)
{
}

testTemp::~testTemp(void)
{
}
template<typename T>
int testTemp::MonitorSignal(T inp, std::vector<T> monVec, int len)
{

return 0;
}

stdafx.h 是:

#pragma once

#include "targetver.h"

#include <stdio.h>
#include <tchar.h>

我在 MSVC 2008 中运行它,每当我尝试构建这段代码时,我都会遇到以下崩溃: enter image description here

最佳答案

模板变量是 c++14 中的新内容。 VS2008 当然没有实现它们。

template <typename T> std::vector<T> m_vMonitorVec;

应该是

template <typename T>
class testTemp {
public:
testTemp(void) { }
~testTemp(void) { }
int MonitorSignal(T x, std::vector<T> const& vec, int len) {
return 0;
}
private:
std::vector<T> m_vMonitorVec;
};

因此我建议内联实现: Why can templates only be implemented in the header file?


PS 您可以报告编译器错误,但他们不会修复旧版本。

关于c++ - Microsoft C++ 优化编译器已停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27113386/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com