如何使用vc ++初始化float数组? [英] How to initialize float array using vc++?

查看:387
本文介绍了如何使用vc ++初始化float数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已初始化如下:

fvariable [100] = {0.0,0.0}在构造函数中,但是出现语法错误.


I have initialized as following:

fvariable[100] = {0.0, 0.0} in constructor but I got syntax error.


Is it not the right way to initialize it?

推荐答案

这应该有帮助:

您不能在对象构造函数(如果有的话).您必须在构造函数块中显式初始化它,例如:
You cannot do that in a object constructor (if I got you). You have to explicitely initialize it inside the constructor block, for instance:
class MyClass
{
  float fvariable[100];

public:
  MyClass()
  {
    for (int n=0; n < sizeof(fvariable)/sizeof(fvariable[0]); n++)
    {
      fvariable[n] = 0.0;
    }
  }
};


:)


也许您只是忘记了; ?而且不要忘了前导 f 告诉编译器您要的是float而不是double.
这应该可以工作:
Maybe you just forgot the ;? And don''t forget the leading f to tell the compiler you want a float and not a double.
This should work:
//declaration time
float fvariable[100] = { 0.0f };

//you can''t do that.
//fvariable[100] = { 0.0f };

//Or you can do as CPallini suggests:
for (int i = 0; i < 100; n++)
    fvariable[i] = 0.0f;



但是它们是其他方式...



But they are other ways...


这篇关于如何使用vc ++初始化float数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆