Win32编程不能包含模板头文件

时间:2019-03-12 05:07:02

标签: templates winapi

我正在使用Visual Studio 2017编写标准的Win32 Windows UI程序。但是,当我尝试将以下头文件包含到MyMainWin.cpp文件(您在其中定义窗口和消息处理)时,它抱怨了许多语法错误。例如,对于类定义“};”末尾的行,它抱怨“';'”之前的“意外标记”。如果我将以下头文件包含在控制台应用程序main.cpp中,则它可以正常工作。为什么?

#ifndef _MY_RAND_H_
#define _MY_RAND_H_

#include <random>
#include <tuple>
#include <iostream>

namespace myown {

void srand(int seed);
int rand();

template<class IntType = int>
class my_uniform_int_distribution {
public:
// types
typedef IntType result_type;
typedef std::pair<int, int> param_type;

// constructors and reset functions
explicit my_uniform_int_distribution(IntType a = 0, IntType b = std::numeric_limits<IntType>::max());
explicit my_uniform_int_distribution(const param_type& parm);
void reset();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& g, const param_type& parm);

// property functions
result_type a() const;
result_type b() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;

private:
typedef typename std::make_unsigned<IntType>::type diff_type;

IntType lower;
IntType upper;
}; //visual studio compiler complains "unexpected token(s) preceding';'" here

//method definition...
}
#endif

0 个答案:

没有答案
相关问题