const int*& vs typedef int* IntPtr
const int*& vs typedef int* IntPtr
为什么我必须将int *
更改为typedef int * IntPtr
才能进行编译?
template <class T>
class A
{
public:
template <class X>
void a(X *x, void (X::*fun)(const T&))
{
}
};
typedef int * IntPtr;
class B
{
public:
B() : a()
{
a.a(this, &B::foo); // this won't work
}
void foo(const int *&) // must replace `int *` here with `IntPtr`
{
}
A<int *> a; // ...and here
};
class C
{
public:
C() : a()
{
a.a(this, &C::foo);
}
void foo(const IntPtr&)
{
}
A<IntPtr> a;
};
我理解为什么typedef很有用,但不理解为什么需要它们。类CCD_ 3编译精细CCD_。
这是来自MSVC++2008编译器的错误:
Error 1 error C2784: 'void A<T>::a(X *,void (__thiscall X::* )(const T &))' : could not deduce template argument for 'void (__thiscall X::* )(const T &)' from 'void (__thiscall B::* )(const int *&)'
const int*&
和typedef int* IntPtr; const IntPtr&
不相同。在第一种情况下,int是常量,在第二种情况下是指针。只有第二种情况与您的模板兼容。
如果你写
void foo(int * const &);
相反,它应该编译并正常工作。
相关文章:
- 为什么在全局范围内使用"extern int a"似乎不行?
- int(c) 和 c-'0' 之间的区别。C++
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 是否可以从int转换为enum类类型
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 向量 <int> a {N, 0} 和 int arr a[N] = {0} 的时间复杂度有什么区别
- 'short int'持有的值溢出,但"自动"不会溢出?
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- 调用'begin(int [n])'没有匹配函数
- 没有显式声明的int[]中的foreach
- 在c++中访问int到类对象的映射时出错
- 为什么我无法更改"set<set>"循环中的值<int>
- 长 长 int 不要 长 int 好
- C++程序在循环后给出奇怪的int值
- typedef int* intptr OR typedef int *intptr;
- 我们可以将所有"int"参数和返回类型替换为 DllImport 方法签名中的"IntPtr"吗?
- const int*& vs typedef int* IntPtr