我想要别名void *变量,以便我可以使用其他名称。这意味着我可以将指针(p)设置为某些内容,并且别名变量(pp)也将设置为相同的地址。对void *指针的常量引用
例如:
class foo {
private:
static void* p; //I just happen to need this for static variable
static const void*& pp;
};
//in cpp:
const void*& foo::pp = foo::p;
GCC抱怨:
error: invalid initialization of reference of type 'const void*&' from expression of type 'void*'
您的声明不符合您的定义:前者是类型`常量无效*&的'(参考指针常量无效),而后者是一个类型`常量无效的* const(常量引用指向const void的指针),它们都不兼容“void指针”。 – 2011-02-06 03:59:11
Adam Rosenfield:哎呀,那是输入错误。实际的代码是'const void *&',仍然是错误的。 – Pubby 2011-02-06 04:04:56