【发布时间】:2011-12-02 12:21:06
【问题描述】:
我有以下 C++ 代码 sn-p:
class T { };
void f(const T**) { }
int main() {
T *x = new T[5];
f(&x);
}
当我尝试编译时,g++ 报告invalid conversion from 'T**' to 'const T**'。我已经完成some research 并且我理解这个错误。典型的解决方法是将f(const T**) 的定义更改为f(const T* const*),这会立即解决问题。
不幸的是,就我而言,f 是另一个库中的函数,我无法更改 f 的定义。如何将x的地址传递给f?
【问题讨论】:
标签: c++ pointers types constants type-conversion