Reputation: 1980
I am trying to define a template member function in a class, and MSVC crashes everytime I try to build this code. I am not sure if this is a bug in Visual Studio 2008. Here is a minimal example.
testTemp.h
header file:
#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);
};
and here is 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;
}
and stdafx.h is:
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
I am running this in MSVC 2008, whenever I try to build this code, I get the following crash:
Upvotes: 1
Views: 1970
Reputation: 393769
Template variables are new in c++14. VS2008 certainly doesn't implement them.
template <typename T> std::vector<T> m_vMonitorVec;
should likely be
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;
};
I suggested inline implementation because of this: Why can templates only be implemented in the header file?
PS You could report a compiler bug but they won't fix that old version.
Upvotes: 5