我想使用此代码定义一些通用指针(?但不是void指针):
class A { templateusing ptr = T*; using ubyte = uint8_t; public: const ptr getColor1() const { return &colors[0]; } const ubyte* getColor2() const { return &colors[0]; } private: ubyte colors[4]; };
但是,getColor1()
不会编译.这两个功能有什么区别?
gcc说:
error: invalid conversion from 'const ubyte* {aka const unsigned char*}' to 'A::ptr{aka unsigned char*}' [-fpermissive]|
更新:
删除的答案说我可以这样做:
//option 1 templateusing const_ptr = const T*;
要么
//option 2 const ptrgetColor() //remove cv-qualifier { return &colors[0]; }
来自option1,
它构建到现在const const
,const const
意味着什么?
来自option2,
为什么只删除cv-qualifier使这个编译?