部分特化非顶级cv限定符在函数签名中被忽略
Partial specialization non-top level cv qualifier ignored in function signature
我试着使用下面的测试用例:
/* Generic implementation */
template <typename T>
struct SpecWrapper {
static void bar(T const* src) {
printf("src[0] = %len", src[0]);
}
};
/* Volatile partial-specialization */
template <typename T>
struct SpecWrapper<T volatile> {
static void bar(T const* src) {
printf("src[0] = %len", src[0]);
}
};
/* Instantiate */
void foo(double volatile const* src) {
SpecWrapper<double volatile>::bar(src);
}
但是使用g++
会产生以下错误test.cxx: In function ‘void foo(const volatile double*)’:
test.cxx:18:38: error: invalid conversion from ‘const volatile double*’ to ‘const double*’ [-fpermissive]
LowLevel<double volatile>::bar(src);
^
test.cxx:12:16: error: initializing argument 1 of ‘static void LowLevel<volatile T>::bar(const T*) [with T = double]’ [-fpermissive]
static void bar(T const* src) {
^
谁能解释一下为什么会出现这个问题?我想到了一些变通方法,但我想首先理解为什么这是一个问题。
应该是
/* Volatile partial-specialization */
template <typename T>
struct SpecWrapper<T volatile> {
static void bar(T volatile const* src) {
printf("src[0] = %len", src[0]);
}
};
因为T
就是double
相关文章:
- 将 cv::Mat 转换为 std::vector 的通用函数
- OpenCV 函数 cv::remap() 的执行时间更长,当程序在两者之间进入睡眠状态时
- OpenCV 与 C++,使用 cv::utils::fs::glob() 函数
- 为什么在某些情况下从函数返回类型中删除 cv 限定符?
- 如何将 cv::mat 对象从 python 模块传递到 c++ 函数并返回返回的 cv::mat 类型为对象?
- C++中相同的CV函数(OpenCV)
- 调用 cv::stereoBM 构造函数时出错
- 如何根据 C++ 中的 cv 限定符选择构造函数
- OpenCV CUDA 函数缺失 - 命名空间"cv:cuda"没有成员"resize"
- 如何有效地传递 std::vector<cv::P oint3f> 的子向量作为参数(不拥有函数)
- 如何使用模板函数从缓冲区(T* 数据数组)创建 cv::Mat
- cv::warpPerspective() 函数的问题
- 以 cv::P oint_<T> 作为参数的模板函数无法编译
- 逐行填充 cv::mat 调用函数
- 嵌套模板参数以及函数参数的 cv 和 ref- 限定符
- 如何在C++中声明一个定义为func(cv::Mat &img)的函数
- cv::line函数是画倒置的线条
- 具有 const cv::Mat 类型的参数将在函数中更改
- Typedef 用于指向 cv 和/或 ref 限定成员函数的指针
- 函数 cv::findChessboardCorners 角不能是 std::vector<cv::P oint2f>