大佬教程收集整理的这篇文章主要介绍了C重复符号,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
基本上,这是结构:
的CMakeLists.txt
add_executable(Game Game/main.cpp Game/rtexture.cpp)
游戏/ main.cpp中
#include "cleanup.h" //... cleanup(foobar);
游戏/ rtexture.cpp
#include "cleanup.h" //... cleanup(foobar);
cleanup.h
//varIoUs includes template<typ@R_675_8371@ T,typ@R_675_8371@... Args> void cleanup(T *t,Args&&... args){ //Cleanup the first item in the list cleanup(t); //Recurse to clean up the remaining arguments cleanup(std::forWARD<Args>(args)...); } /* * these specializations serve to free the passed argument and also provide the * base cases for the recursive call above,eg. when args is only a single item * one of the specializations below will be called by * Cleanup(std::forWARD<Args>(args)...),ending the recursion * We also make it safe to pass nullptrs to handle situations where we * don't want to bother finding out which values Failed to load (and thus are null) * but rather just want to clean everything up and let cleanup sort it out */ template<> void cleanup<SDL_Window>(SDL_Window *win){ if (!win){ return; } SDL_DestroyWindow(win); } template<> void cleanup<SDL_Renderer>(SDL_Renderer *ren){ if (!ren){ return; } SDL_DestroyRenderer(ren); } template<> void cleanup<SDL_Texture>(SDL_Texture *teX){ if (!teX){ return; } SDL_DestroyTexture(teX); } template<> void cleanup<SDL_Surface>(SDL_Surface *surf){ if (!surf){ return; } SDL_FreeSurface(surf); }
如果有人问,我确实从教程中获取了这个“cleanup.h”,但是却找不到将它包含在多个类中的方法,而没有声明重复的符号.
Home at cruz45488-y19-MBA13-12 in ~/desktop/sdlworkspace/tmp $make Linking CXX executable Game duplicate symbol __ZN5RUtil7cleanupI10SDL_WindowjeEEvPT_DpOT0_ in: CMakeFiles/Game.dir/Game/main.cpp.o CMakeFiles/Game.dir/Game/rtexture.cpp.o duplicate symbol __ZN5RUtil7cleanupI12SDL_RendererjeEEvPT_DpOT0_ in: CMakeFiles/Game.dir/Game/main.cpp.o CMakeFiles/Game.dir/Game/rtexture.cpp.o duplicate symbol __ZN5RUtil7cleanupI11SDL_TexturejeEEvPT_DpOT0_ in: CMakeFiles/Game.dir/Game/main.cpp.o CMakeFiles/Game.dir/Game/rtexture.cpp.o duplicate symbol __ZN5RUtil7cleanupI11SDL_SurfacejeEEvPT_DpOT0_ in: CMakeFiles/Game.dir/Game/main.cpp.o CMakeFiles/Game.dir/Game/rtexture.cpp.o
有帮助吗?谢谢.
以上是大佬教程为你收集整理的C重复符号全部内容,希望文章能够帮你解决C重复符号所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。