Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.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++ *.cpp文件中的Typedef模板类指针_C++_Templates_Pointers_Typedef - Fatal编程技术网

C++ *.cpp文件中的Typedef模板类指针

C++ *.cpp文件中的Typedef模板类指针,c++,templates,pointers,typedef,C++,Templates,Pointers,Typedef,在我的标题中,我得到了一个外部库模板的typedef和一个函数,如: #include "ExternalFancyLib.h" class Fancy { public: //... typedef FancyClass<int , 3> FancyClassType; FancyClassType::Pointer FancyFunction (); } 我的始终友好的编译器告诉我“:”后面必须跟一个类或命名空间,引用FancyClassType 有没有办法优

在我的标题中,我得到了一个外部库模板的typedef和一个函数,如:

#include "ExternalFancyLib.h"
class Fancy
{
public:

  //...

  typedef FancyClass<int , 3> FancyClassType;

  FancyClassType::Pointer FancyFunction ();
}
我的始终友好的编译器告诉我“:”后面必须跟一个类或命名空间,引用FancyClassType

有没有办法优雅地解决这个问题


Cheers Usche

FancyClassType
在您的
Fancy
类中定义,因此您也必须指定:

Fancy::FancyClassType::Pointer Fancy::FancyFunction(){}

FancyClassType::Pointer
使用当前作用域进行查找。在类定义中,这包括
Fancy
中的定义。在Cpp文件中,名称在全局范围内解析,因此它将呈现
::FancyClassType::Pointer
(此处忽略名称空间)。这是没有定义的。

我强烈感觉到您的
FancyClassType
需要取代
FancyClass
。此外,在使用
typedef
时,您还需要参考
Fancy:

cpp文件中的代码应如下所示:

#include "Fancy.h"

Fancy::FancyClassType::Pointer Fancy::FancyFunction (){
// do and return smth
}
否则,您实际上不是在调用您创建的
typedef

我能想到的另一种方法是添加
::指针
,指向只需调用的
typedef

Fancy::FancyClassType Fancy::FancyFunction (){
    // do and return smth
    }

这是我能想到的最好的了。。。希望有帮助

请发布准确完整的编译器错误错误C2653:“FancyClassType”:不是类或命名空间名称您在提出问题时应该非常明确,并确保添加适当的代码。最初的描述没有提到
typedef
嵌套在类定义中,这是核心问题。写好问题是获得好答案的一半以上。啊,ofc!谢谢太棒了!
Fancy::FancyClassType Fancy::FancyFunction (){
    // do and return smth
    }