Xcode中实例化后的显式专门化 我有一些C++代码,像
头文件a.hXcode中实例化后的显式专门化 我有一些C++代码,像,c++,xcode,C++,Xcode,头文件a.h #ifndef A_H #define A_H template <class Real> class GridGraph2 { protected: class Vertex { void SetWeight (int iDX, int iDY, Real fWeight) {
#ifndef A_H
#define A_H
template <class Real>
class GridGraph2
{
protected:
class Vertex
{
void SetWeight (int iDX, int iDY, Real fWeight)
{
m_afWeight[GridGraph2<Real>::ms_aaiIndex[iDY+1][iDX+1]] = fWeight;
}
Real GetWeight (int iDX, int iDY) const
{
return m_afWeight[GridGraph2<Real>::ms_aaiIndex[iDY+1][iDX+1]];
}
private:
Real m_afWeight[8];
};
friend class Vertex;
static const int ms_aaiIndex[3][3]; // index[dy][dx]
};
typedef GridGraph2<float> GridGraph2f;
#endif
\ifndef A\u H
#定义一个
模板
类GridGraph2
{
受保护的:
类顶点
{
无效设定重量(整数iDX、整数iDY、实际重量)
{
m_afWeight[GridGraph2::ms_aaiIndex[iDY+1][iDX+1]]=fWeight;
}
实GetWeight(intidx,intidy)常量
{
返回m_afWeight[GridGraph2::ms_aaiIndex[iDY+1][iDX+1];
}
私人:
实际单位重量[8];
};
朋友类顶点;
静态常量int ms_aaiIndex[3][3];//索引[dy][dx]
};
typedef GridGraph2 GridGraph2f;
#恩迪夫
代码文件a.cpp
#include "a.h"
template
class GridGraph2<float>;
template<>
const int GridGraph2<float>::ms_aaiIndex[3][3] =
{
{0,1,2}, {3,-1,4}, {5,6,7}
};
#包括“a.h”
模板
类GridGraph2;
模板
const int GridGraph2::ms_aaiIndex[3][3]=
{
{0,1,2}, {3,-1,4}, {5,6,7}
};
但是,当我尝试在clion中构建时,会出现一些错误:
错误:实例化后“ms_aaiIndex”的显式专门化
const int GridGraph2::ms_aaiIndex[3][3]=
这里首先需要隐式实例化
m_afWeight[GridGraph2::ms_aaiIndex[iDY+1][iDX+1]]=fWeight代码>
我想知道我应该在哪里修改代码才能成功构建,以及为什么编译器在实例化后说ms_aaiIndex
显式专门化
我使用xcode命令工具来构建它。但在windows中使用mingw构建它时没有错误 #包括“a.h”
#include "a.h"
/*
* remove this
*
template
class GridGraph2<float>;
*
*/
template<>
const int GridGraph2<float>::ms_aaiIndex[3][3] =
{
{0,1,2}, {3,-1,4}, {5,6,7}
};
/*
*去掉这个
*
模板
类GridGraph2;
*
*/
模板
const int GridGraph2::ms_aaiIndex[3][3]=
{
{0,1,2}, {3,-1,4}, {5,6,7}
};
如何在没有类名的情况下完成这项工作,似乎对我不起作用。我不确定“没有类名”是什么意思?您好,我指的是不属于类或命名空间的模板化函数。