指针调用变为引用指针调用
Call by pointer become call by reference to pointer
>我有几个错误,我认为我正在调用一个函数并通过指针提供一些变量,通过值提供一些变量。但是,我收到编译器错误,因为不知何故,指针变量的调用被更改为对指针的引用。
这是错误
g++ -Wall -c -std=c++11 -I. -c -o SDL_Lesson2.o SDL_Lesson2.cpp
SDL_Lesson2.cpp: In function ‘int main(int, char**)’:
SDL_Lesson2.cpp:56:42: error: call of overloaded ‘renderTexture(SDL_Texture*&,
SDL_Renderer*&, int, int)’ is ambiguous
SDL_Lesson2.cpp:56:42: note: candidates are:
In file included from SDL_Lesson2.cpp:8:0:
sdlWrapper.hpp:40:6: note: void renderTexture(SDL_Texture*, SDL_Renderer*, int, int)
sdlWrapper.hpp:54:6: note: void renderTexture(SDL_Texture*, SDL_Renderer*, int, int,
SDL_Rect*)
SDL_Lesson2.cpp:57:43: error: call of overloaded ‘renderTexture(SDL_Texture*&,
SDL_Renderer*&, int&, int)’ is ambiguous
SDL_Lesson2.cpp:57:43: note: candidates are:
In file included from SDL_Lesson2.cpp:8:0:
sdlWrapper.hpp:40:6: note: void renderTexture(SDL_Texture*, SDL_Renderer*, int, int)
sdlWrapper.hpp:54:6: note: void renderTexture(SDL_Texture*, SDL_Renderer*, int, int,
SDL_Rect*)
这些行中的代码是:
SDL_Renderer *renderer = SDL_CreateRenderer(win, -1,
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
SDL_Texture* background = loadTexture("./background.bmp", renderer);
SDL_Texture* image = loadTexture("./image.bmp", renderer);
...
int bW, bH;
SDL_QueryTexture(background, NULL, NULL, &bW, &bH);
renderTexture(background, renderer, 0, 0);
renderTexture(background, renderer, bW, 0);
所以,我想知道,为什么电话模棱两可。在我看来,renderTexture(background, renderer, 0, 0)
显然是renderTexture(SDL_Texture*, SDL_Renderer*, int, int)
.我错了,但我不知道为什么。
此外,在这两行之间,前int
从按值调用更改为按引用调用。这对我来说也是一个谜。
我相信问题来自两个重载版本。
void renderTexture(SDL_Texture *tex, SDL_Renderer *ren, int x, int y, int w, int h);
和
void renderTexture(SDL_Texture *tex, SDL_Renderer *ren, SDL_Rect dst,
SDL_Rect *clip = nullptr);
这些版本,对我来说看起来不一样。但是由于SDL_Rect结构中只有四个整数,我可以看到编译器可能会将它们相互混淆。
我应该取消这些功能之一吗?还是问题出在其他地方,而我只是通过删除其中一个功能来隐藏问题?
关于第二个问题,第二个调用注册为 int&,因为它可以选择完成该签名。 文本只能按值传递,而变量可以按引用或值传递。 因此,0
只能匹配需要int
的签名,而bW
可以匹配需要int
或int&
的签名。
关于第一个问题,你确定你已经完全从sdlWrapper.hpp复制了这两行吗? 候选人签名似乎与您提供的签名不匹配。
相关文章:
- 为什么使用 "this" 指针调用派生成员函数?
- 当使用通配符和null指针调用函数时,对输出的说明
- Visual c ++,使用字符串引用/指针调用 dll 函数
- 使用基类指针调用基类的值构造函数的语法是什么?
- 是否可以使用函数指针调用虚拟析构函数?
- 使用C++指针调用 python 函数
- 如何使用接口指针调用方法,该指针是其具体类的一部分,而不是接口的一部分
- 是否可以使用非常量指针调用非常量函数,以及当两个unique_ptrs指向同一个对象时程序的行为方式?
- 在将派生类指针类型转换为派生类指针后,从基类指针调用派生类函数
- 通过指针调用模板类成员函数 [为什么这是有效的 c++]?
- 从带有参数的基函数指针调用基方法
- 使用唯一指针调用函数会使我的程序崩溃
- C++::在构造函数退出之前通过指针调用成员函数
- 有没有办法在没有虚拟的情况下使用基类指针调用派生类函数
- 什么时候用指针调用C++类构造函数
- C++ - 使用变量指针调用函数
- 为什么我可以通过野生指针调用成员函数
- 从指针调用方法时出现分段错误
- 为什么使用指向函数的指针调用虚函数时不需要指针"this"?
- C++ abort() 在函数内的抽象类对象指针调用上