std :: vector问题 [英] std::vector problems

查看:77
本文介绍了std :: vector问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我在类声明中将以下行添加到我的代码中:


std :: vector< Date> m_duedates(100);


我也尝试过:


std :: vector< Date> m_duedates(100,Date());


我的程序在没有这一行的情况下编译并运行正常,但是有了它(上面的第一个

样式)我得到了错误:


错误C2059:语法错误:''常数''


日期是一个带有默认构造函数的类Date()


帮助没有帮助解释这个错误的原因。任何想法??


我只是要使用Date类型的数组,但编译一直在抛出




谢谢!


数学


Hi,

I added the following line to my code within a class declaration:

std::vector<Date> m_duedates(100);

I also tried:

std::vector<Date> m_duedates(100, Date());

My program compiles and runs fine without this line, but with it (the first
style above) I get the error:

error C2059: syntax error : ''constant''

Date is a class with a default constructor Date()

The help didn''t help explain the cause of this error. Any ideas??

I was just going to use an array of type Date but the compile kept throwing up
on that too.

Thanks!

Math


推荐答案

Honestmath写道:
Honestmath wrote:
我的程序在没有这一行的情况下编译并运行良好,但有了它(上面的第一个
风格)我收到错误:


我不知道C2059的错误是什么意思。我的编译器没有生成这个

错误。

Date是一个带有默认构造函数的类Date()

帮助没有''帮助解释此错误的原因。任何想法??

我只是要使用Date类型的数组,但编译也一直在抛出
My program compiles and runs fine without this line, but with it (the first
style above) I get the error:

error C2059: syntax error : ''constant''
I have no idea what error C2059 means. My compiler doesn''t generate this
error.

Date is a class with a default constructor Date()

The help didn''t help explain the cause of this error. Any ideas??

I was just going to use an array of type Date but the compile kept throwing up
on that too.




如果没有看到* Date *课,我就无法帮助你。


KPB



I can''t help you without seeing your *Date* class.

KPB


>
std :: vector< Date> m_duedates(100);

我也尝试过:

std :: vector< Date> m_duedates(100,Date());

我的程序在没有这一行的情况下编译并运行良好,但有了它(上面的
第一个
样式)我得到错误:
std::vector<Date> m_duedates(100);

I also tried:

std::vector<Date> m_duedates(100, Date());

My program compiles and runs fine without this line, but with it (the
first
style above) I get the error:




试试这个:


class tet

{

std ::矢量<日期> m_duedates;

public:

tet():m_duedates(100){}

};



try this :

class tet
{
std::vector<Date> m_duedates;
public:
tet() : m_duedates(100) {}
};


Honestmath写道:
Honestmath wrote:
我在类声明中将以下行添加到我的代码中:

std :: vector< Date> m_duedates(100);


您无法初始化类_definition_中的成员(我确定

您的意思是定义而不是声明)。


非静态数据成员需要在构造函数中初始化

初始化列表。在你最喜欢的C ++书中阅读它。

我也尝试过:

std :: vector< Date> m_duedates(100,Date());

我的程序在没有这一行的情况下编译并运行正常,但是使用它(上面的第一个
样式)我收到错误:
<错误C2059:语法错误:''常数''

日期是一个带有默认构造函数的类Date()

帮助没有帮助解释导致此错误。任何想法??

我只是要使用Date类型的数组,但编译也一直在抛出
I added the following line to my code within a class declaration:

std::vector<Date> m_duedates(100);
You cannot initialise members inside a class _definition_ (I am sure
you meant definition and not declaration).

Non-static data members need to be initialised in the constructor
initialiser list. Read about it in your favourite C++ book.

I also tried:

std::vector<Date> m_duedates(100, Date());

My program compiles and runs fine without this line, but with it (the first
style above) I get the error:

error C2059: syntax error : ''constant''

Date is a class with a default constructor Date()

The help didn''t help explain the cause of this error. Any ideas??

I was just going to use an array of type Date but the compile kept throwing up
on that too.




V



V


这篇关于std :: vector问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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