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

标签 c++ visual-studio templates

我试图在一个类中定义一个模板成员函数,但每次我尝试构建这段代码时 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/

相关文章:

node.js - 什么是 Node 的 NODE_ENV 的 Golang 等价物

c++ - SDL_mixer WAVE 音频格式质量差

c++ - 如何在C++中跨平台远程过程调用(Linux/Win)

尝试从 Visual Studio 2015 提交时出现 Git 错误(文件 opensdf)

c# - 在 Visual Studio 2010 中查看控制台的输出?

c++:类外的模板变量

采用继承类的 C++ 非类型模板参数

c++ - 有没有一种简单的方法可以在初始化后填充二维数组?

c++ - 从自身内部替换 std::function(通过 move 赋值到 *this?)

c# - 在 C# 中播放声音 - 使用所有方法中的哪一种?