简体   繁体   English

在旧的c ++(

[英]In old c++ (<c++11), initializing struct gets errors

struct Material {
    glm::vec3 ambient;
    glm::vec3 diffuse;
    glm::vec3 specular;
    float shininess;
};

Material emerald{ { 0.0215f, 0.1745f, 0.0215f },{ 0.07568f, 0.61424f, 0.07568f },{ 0.633f, 0.727811f, 0.633f },0.6f };

This works perfectly fine in C++11, but I can't figure out how to fix this in C++ < C++11. 这在C ++ 11中可以很好地工作,但是我不知道如何在C ++ <C ++ 11中解决此问题。 I migrated to VS2010 for a reason, and need to fix these errors. 我迁移到VS2010是有原因的,需要修复这些错误。

the error i get is: 我得到的错误是:

looks like a function definition, but there is no formal parameter list; skipping apparent body

Thank you in advance. 先感谢您。

glm::vec3 (is a typedef for a class that) has a constructor that accepts three arguments, so (before C++11) you can't use uniform or aggregate initialisation for your struct. glm::vec3 (是typedef为一类),有三个参数,所以(在C ++ 11),你不能使用统一的或累计初始化为你的结构构造。

To do what you wish, change 做你想做的,改变

Material emerald{ { 0.0215f, 0.1745f, 0.0215f },{ 0.07568f, 0.61424f, 0.07568f },{ 0.633f, 0.727811f, 0.633f },0.6f };

to

Material emerald = { glm::vec3(0.0215f, 0.1745f, 0.0215f),
                  glm::vec3(0.07568f, 0.61424f, 0.07568f),
                  glm::vec3(0.633f, 0.727811f, 0.633f),
                  0.6f };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM