Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在C++;内联+;模板上下文? 我正面临一个有趣的问题:我在Visual C++ 6中有一个MFC应用程序项目。由于MFC或C++标准中有很多更改,所以我想将应用程序移植到VisualStudio 2010。这很好,但我现在面临一个警告,我无法处理_C++_Visual Studio 2010_Templates_Inline_Afx - Fatal编程技术网

如何在C++;内联+;模板上下文? 我正面临一个有趣的问题:我在Visual C++ 6中有一个MFC应用程序项目。由于MFC或C++标准中有很多更改,所以我想将应用程序移植到VisualStudio 2010。这很好,但我现在面临一个警告,我无法处理

如何在C++;内联+;模板上下文? 我正面临一个有趣的问题:我在Visual C++ 6中有一个MFC应用程序项目。由于MFC或C++标准中有很多更改,所以我想将应用程序移植到VisualStudio 2010。这很好,但我现在面临一个警告,我无法处理,c++,visual-studio-2010,templates,inline,afx,C++,Visual Studio 2010,Templates,Inline,Afx,头文件具有以下类定义: template <class T> class foo : public CObject { // ... // other stuff // ... private: CTypedPtrMap<CMapWordToPtr, const long, T*> oElementMap; void some_stuff(); } 请与我分享有关此问题的任何想法,我如何在不更改容器的oElementMap定义和行为、不在项目设置中全局抑

头文件具有以下类定义:

template <class T>
class foo : public CObject
{
// ...
// other stuff
// ...
private:
    CTypedPtrMap<CMapWordToPtr, const long, T*> oElementMap;
    void some_stuff();
}
请与我分享有关此问题的任何想法,我如何在不更改容器的
oElementMap
定义和行为、不在项目设置中全局抑制/禁用此警告以及不更改VS2010提供的
afxtempl.h
文件的情况下解决此警告

感谢您的帮助:


Andrew

我将其定义替换为:
CMap oElementMap。我不确定它是否是旧地图定义的“长对应物”,因此我做了几个测试来比较它们


解决方案最终是这样的。

如果您编写
oElementMap.RemoveKey(static_cast(nIndex)),是否仍然会收到警告
?如果您有太多的关键字用于
WORD
,并且必须使用
long
,那么使用
CMapWordToPtr
作为基类在某一点上无论如何都会失败,对吗?BoBTFish:是的,您是对的。问题是,不存在
CMapDwordToPtr
或类似的东西,它会很有用……因此,如果不更改
oElementMap
的定义,就不应该试图消除警告。这是一个真正的问题,你应该改变定义。但我同意,这并不是马上就能看出什么。
template <class T>
void foo::some_stuff()
{
// ...
// other stuff
// ...
    int nIndex = 0;
// ...
// other stuff
// ...
    oElementMap.RemoveKey(nIndex);
}
#pragma warning (disable: 4244)
// expression
#pragma warning (default: 4244)