简体   繁体   English

没有typedef的结构-不能在指向成员的指针中使用

[英]struct without typedef - cannot use in a pointer-to-member

I have a simple structure and I want a pointer-to-member c. 我有一个简单的结构,我想要一个指向成员的指针c。 I'm using MSVC2012 and if I don't declare the struct abc as a type definition (typedef), I can't use it.. how come? 我正在使用MSVC2012,如果我不将struct abc声明为类型定义(typedef),那么我将无法使用它。

struct abc
{
    int a;
    int b;
    char c;
};

char (struct abc)::*ptt1 = &(struct abc)::c; // Error: error C2144: syntax error : 'abc' should be preceded by ')'

typedef struct abc;
char abc::*ptt1 = &abc::c; // Compiles just fine

if I don't declare the struct abc as a type definition (typedef), I can't use it.. how come? 如果我没有将struct abc声明为类型定义(typedef),那么我将无法使用它。

You can, and you don't need the struct keyword, nor the typedef . 可以,并且不需要struct关键字,也不需要typedef Just do this: 只要这样做:

char abc::*ptt1 = &abc::c;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM