小编ElG*_*ito的帖子

std::vector 的可变模板打包参数

我是模板的新手,我真的不明白为什么这不起作用。我希望用这些值构造向量。

主程序


template <typename ...T>
void int_printf(T ...args)
{
    std::vector<T> vec = {args...};

    for(auto& v:vec)
    {
        std::cout << v << std::endl;
    }
}

int main()
{
    int_printf(1,2,3,4);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

预期结果

1
2
3
4
Run Code Online (Sandbox Code Playgroud)

msvc 编译器出错(已翻译)

1
2
3
4
Run Code Online (Sandbox Code Playgroud)

c++ templates variadic-templates

2
推荐指数
1
解决办法
138
查看次数

OpenGL 着色器有时可以编译,有时则不能

我正在学习 OpenGL,当我运行该程序时,有时可以工作(红色三角形),有时则不能(白色三角形且没有三角形)。我正在使用 makefiles 使用 msvc(命令行中的 cl.exe)来编译它。这是该程序的简化版本,请告诉我您是否也遇到同样的奇怪行为。

预期结果(运行的 10%)

:D

越野车结果(90% 的运行)

:C

:C

主程序

#define SDL_MAIN_HANDLED
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <sstream>
#include <GL/glew.h>
#include <SDL2/SDL.h>
//Loading the file, I suspect that the shaders sometimes are not loaded properly but I'm not sure.
std::string loadFile(const std::string filepath)
{
    std::ifstream file(filepath.c_str());
    if(!file.is_open())
    {
        std::cerr << "Error loading Shader" << std::endl;
        std::exit(1);
    }
    std::string output = std::string((std::istreambuf_iterator<char>(file)),std::istreambuf_iterator<char>());
    return output;
}
//Just error checking (Probably I should include the shader …
Run Code Online (Sandbox Code Playgroud)

c++ opengl shader vertex-shader fragment-shader

2
推荐指数
1
解决办法
553
查看次数