本文介绍了带功能指针声明的错误C2059的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试定义一个返回指针的函数指针。 函数的返回类型将是一个指针 如下所示的结构,但是我得到了错误C2059:语法错误:'< ;编译时标记> :: *'。

I try to define a function pointer that returns a pointer. The return type of the function would be a pointer a struct as shown below, but I got the error C2059: syntax error : '<tag>::*' during compilation.

struct MyStruct{
   public:
      MyStruct(int param1, int aram2);   
      ... ...
};

typedef struct MyStruct FAR *LPMyStruct;

typedef LPMyStruct (CMyApp::*GetMyStructPtrFunc)();

请注意,MysStruct和LPMyStruct是在单独DLL的herder文件中定义的。

Note that MysStruct and LPMyStruct are defined in a herder file of a separate DLL.

有什么可能出错的建议? 真的很感激。

Any suggestion of what could be wrong there?  Really appreciate.

jwang

推荐答案

一个非常小的样本做同样的事情:

A really small sample that does the same thing:

struct test_struct
{

};

typedef test_struct *ptr_test_struct;

class myclass;

typedef ptr_test_struct(myclass::*get_struct)();

在VC2015和2017 RC上干净地编译,所以问题不在于代码本身。预处理器的输出,看你是否有任何惊人的宏扩展。 (您可以在配置属性 - > C / C ++ - >预处理器 - >预处理
下的项目属性中将其启用到文件中。)

Compiles cleanly on VC2015 and 2017 RC, so the problem isn't with the bit of code itself. The output of the pre-processor to see if you have any surprise macro expansions too. (You can enable this in the project properties under Configuration Properties->C/C++->Preprocessor->Preprocess to a file.)


这篇关于带功能指针声明的错误C2059的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 13:28