通过更改传递的值,是否有任何方法可以使用相同的模板类型而具有不同的代码?即:
template <bool>
class container;
Run Code Online (Sandbox Code Playgroud)
并container<true>生成不同的代码container<false>?
如果没有,有什么替代品吗?
我正在尝试翻译一个 qt QML 应用程序,其中充满了
tr("string");
Run Code Online (Sandbox Code Playgroud)
在所有地方,如果我在应用程序启动之前设置翻译器,它会完美运行,但我在即时执行此操作时遇到麻烦。唯一的解决方案似乎是空字符串 hack,但我不想搜索每个“tr”并添加空字符串
我正在尝试使用 SDL 渲染一个点,但似乎无法获取要渲染的点。我在代码中没有收到任何错误,并且正在编译,但是窗口上没有出现任何内容。
代码:
#include <iostream>
#include <SDL2/SDL.h>
using namespace std;
int main() {
const int windowHeight = 600;
const int windowWidth = 800;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
return 1;
cout << "Initialization failed" << endl;
}
SDL_Window *window = SDL_CreateWindow("Practice making sdl Window",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, windowWidth,
windowHeight, SDL_WINDOW_SHOWN);
if (window == NULL) {
SDL_Quit();
return 2;
}
SDL_Renderer *s;
const int pointLocationx = windowWidth/2;
const int pointLocationy = windowHeight/2;
SDL_RenderDrawPoint(s, pointLocationx, pointLocationy);
bool quit = false;
SDL_Event event; …Run Code Online (Sandbox Code Playgroud)