473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

std::vector problems

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


Jul 22 '05 #1
16 2145
KPB
Honestmath wrote:
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.


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

KPB
Jul 22 '05 #2
>
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:


try this :

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

Jul 22 '05 #3
Honestmath wrote:
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
Jul 22 '05 #4
KPB
cyrusNew wrote:
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:

try this :

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


Yep... sorry to the original OP about my last post. Yeah, since you
declared this vector as a class member, your declarations won't work as
written.

KPB
Jul 22 '05 #5
KPB wrote:
Honestmath wrote:
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.

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


Too bad. There is no need to actually see the Date class because the OP
was trying to initialise a 'vector'.

Similar to this:

#include <vector>
class A {
std::vector<int> blah(100); // will produce the same error
};

it needs to be

#include <vector>
class A {
std::vector<int> blah; // declaration only!
public:
A() : blah(100) {}
};

V
Jul 22 '05 #6
KPB
Victor Bazarov wrote:
KPB wrote:
Honestmath wrote:
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.


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

Too bad. There is no need to actually see the Date class because the OP
was trying to initialise a 'vector'.

Similar to this:

#include <vector>
class A {
std::vector<int> blah(100); // will produce the same error
};

it needs to be

#include <vector>
class A {
std::vector<int> blah; // declaration only!
public:
A() : blah(100) {}
};

V


ok
Jul 22 '05 #7
KPB
Victor Bazarov wrote:
Too bad. There is no need to actually see the Date class because the OP
was trying to initialise a 'vector'.


Yes but after looking at his question further, he didn't acutally say
that it was a class member that he was trying to initialize, did he?

It could've been a line written in a member function defn. within a
class def, right? Highly unlikely but possible. If this were the case,
his vector declarations should've worked.

The point is, he didn't say it was a class member so at first, I didn't
register it as a class member. Kudos to you for reading between the lines.

Do you see my point now or can I expect more of these snide little
remarks from you?

Thanks,
KPB

Jul 22 '05 #8

Uzytkownik "KPB" <k@w.net> napisal w wiadomosci
news:yH*******************@fe10.lga...
Victor Bazarov wrote:
Too bad. There is no need to actually see the Date class because the OP
was trying to initialise a 'vector'.


Yes but after looking at his question further, he didn't acutally say that
it was a class member that he was trying to initialize, did he?

It could've been a line written in a member function defn. within a class
def, right? Highly unlikely but possible. If this were the case, his
vector declarations should've worked.

The point is, he didn't say it was a class member so at first, I didn't
register it as a class member. Kudos to you for reading between the lines.

Do you see my point now or can I expect more of these snide little remarks
from you?

Thanks,
KPB

exactly, I actually wrote a quick example code in MSVC and it printed error
C2059 :)
Jul 22 '05 #9
KPB wrote:
Victor Bazarov wrote:
Too bad. There is no need to actually see the Date class because the OP
was trying to initialise a 'vector'.

Yes but after looking at his question further, he didn't acutally say
that it was a class member that he was trying to initialize, did he?


Well, reading the very first sentence in the original post, I see

<< I added the following line to my code within a class declaration:
std::vector<Date> m_duedates(100); >>

what else could it be but a class member? "within a class declaration"
should have given you enough of a clue.

It could've been a line written in a member function defn. within a
class def, right? Highly unlikely but possible. If this were the case,
his vector declarations should've worked.
Yes, it should have. But it didn't. Couldn't that be a clue in itself?

You know how to initialise a vector, apparently. And how screwed up
should the 'Date' class be to make a compiler barf at both

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

_and_

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

by complaining about the constant '100'?
The point is, he didn't say it was a class member so at first, I didn't
register it as a class member. Kudos to you for reading between the lines.
Thanks.
Do you see my point now or can I expect more of these snide little
remarks from you?


Well you're trying to read between even finer lines than I could ever.
If you consider my remarks as snide and little, I'll stop. Sorry I
bothered you.

V
Jul 22 '05 #10
KPB
Victor Bazarov wrote:
KPB wrote:
Victor Bazarov wrote:
Too bad. There is no need to actually see the Date class because the OP
was trying to initialise a 'vector'.
Yes but after looking at his question further, he didn't acutally say
that it was a class member that he was trying to initialize, did he?

Well, reading the very first sentence in the original post, I see

<< I added the following line to my code within a class declaration:
std::vector<Date> m_duedates(100); >>

what else could it be but a class member? "within a class declaration"
should have given you enough of a clue.


It could easily have been an inlined function definition. This could
also be "within a class declaration" as you know. So "within a class
declaration" wasn't enough info for me to help the OP.

I only realized that it was a class member after looking at the m_
prefix of the variable name. Not exactly the greatest of "clues" to go
by here.

It could've been a line written in a member function defn. within a
class def, right? Highly unlikely but possible. If this were the case,
his vector declarations should've worked.

Yes, it should have. But it didn't. Couldn't that be a clue in itself?


Not exactly. That's why I wondered what the Date class looked like.
Perhaps the OP made the operator = function private and unimplemented?
That could cause some problems using std::vector, correct? Again, not
likely but it's always better to solve the problem when the bullshit is
out of the way.

Seeing the Date class could've helped me determine if it was even
allowed to be an element of std::vector<>.

You know how to initialise a vector, apparently. And how screwed up
should the 'Date' class be to make a compiler barf at both

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

_and_

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

by complaining about the constant '100'?
See my remark above about why I considered the Date class. I merely took
a wrong turn in my *debugging*. You've never done that?
The point is, he didn't say it was a class member so at first, I
didn't register it as a class member. Kudos to you for reading between
the lines.

Thanks.
Do you see my point now or can I expect more of these snide little
remarks from you?

Well you're trying to read between even finer lines than I could ever.
If you consider my remarks as snide and little, I'll stop. Sorry I
bothered you.


I'm just attempting to be as detailed as you seem to be; albeit with
less ego.

If you're here to teach, I'll be happy to learn from you. If you're here
to belittle, I'll just *PLONK* you.

KPB
Jul 22 '05 #11
X-No-archive: yes
"KPB" <k@w.net> wrote...
[...]
If you're here to teach, I'll be happy to learn from you. If you're here
to belittle, I'll just *PLONK* you.


I have no intention to belittle anyone. And I am not here to teach.
But I am here regardless of whether somebody wants that or not. Plonk
me if you must (and I recommend you to do so if you feel offended by my
style of sharing my point of view), it will not affect me in the least.

May your stay in this newsgroup be more enjoyable than your first day.
To everyone.

Victor
Jul 22 '05 #12
KPB
Victor Bazarov wrote:
And I am not here to teach.
Again, my mistake. Most of your posts here suggested otherwise. I've
lurked here for awhile and don't see you asking questions, just
answering them so I thought teaching is what you were here for.
But I am here regardless of whether somebody wants that or not. Plonk
me if you must (and I recommend you to do so if you feel offended by my
style of sharing my point of view), it will not affect me in the least.
What offends me is your lack of regard for my point of view on this
subject. Your *style* seems to be *I'm right... you're wrong so fuck
you*. Yeah.. that's offensive.

I saw this:

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

And made the incorrect assumption that it was an object instantiation.
In my mind, no one could possibly write this statement as a class member
so I had dismissed it as such.

When you possess some experience in some skill, you sometimes overlook
the beginner's mistakes that you used to make. That's what happened to
me here. I glossed at the code itself and didn't correctly interpret the
rest of the OP's concerns.

But your freaking attitude was... how could it be anything else? How
could you think anything else?

You don't even have the balls to say that maybe my point of view wasn't
so *left field* given the info.

Hey, I'll take the *reading comprehension* hit for this one but it was
an understandable mistake.
May your stay in this newsgroup be more enjoyable than your first day.
To everyone.


Hey, don't jump on my balls and I won't jump back.

KPB


Jul 22 '05 #13
"KPB" <k@w.net> wrote in message news:Ft*******************@fe10.lga...
Victor Bazarov wrote:
And I am not here to teach.


Again, my mistake. Most of your posts here suggested otherwise. I've
lurked here for awhile and don't see you asking questions, just answering
them so I thought teaching is what you were here for.
But I am here regardless of whether somebody wants that or not. Plonk
me if you must (and I recommend you to do so if you feel offended by my
style of sharing my point of view), it will not affect me in the least.


What offends me is your lack of regard for my point of view on this
subject. Your *style* seems to be *I'm right... you're wrong so fuck you*.
Yeah.. that's offensive.

I saw this:

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

And made the incorrect assumption that it was an object instantiation. In
my mind, no one could possibly write this statement as a class member so I
had dismissed it as such.

When you possess some experience in some skill, you sometimes overlook the
beginner's mistakes that you used to make. That's what happened to me
here. I glossed at the code itself and didn't correctly interpret the rest
of the OP's concerns.

But your freaking attitude was... how could it be anything else? How could
you think anything else?

You don't even have the balls to say that maybe my point of view wasn't so
*left field* given the info.

Hey, I'll take the *reading comprehension* hit for this one but it was
an understandable mistake.
May your stay in this newsgroup be more enjoyable than your first day.
To everyone.


Hey, don't jump on my balls and I won't jump back.

KPB

When you have contributed 5% of what Victor has to this newsgroup perhaps
you will have the credibility to make such statements. That will take you
quite a while. In the meantime I counsel politeness.

--
Cy
http://home.rochester.rr.com/cyhome/
Jul 22 '05 #14
KPB wrote:
But I am here regardless of whether somebody wants that or not. Plonk
me if you must (and I recommend you to do so if you feel offended by my
style of sharing my point of view), it will not affect me in the least.

What offends me is your lack of regard for my point of view on this
subject. Your *style* seems to be *I'm right... you're wrong so fuck
you*. Yeah.. that's offensive.


<snip>

May I suggest you two continue this discussion in
private?
Jonathan
Jul 22 '05 #15
KPB
Cy Edmunds wrote:

When you have contributed 5% of what Victor has to this newsgroup perhaps
you will have the credibility to make such statements. That will take you
quite a while. In the meantime I counsel politeness.


So I have to be polite and take his snide shit just because he happens
to have been around a NG longer?

I'm sorry but contribution has nothing to do with this. If this guy were
Bjarne Stroustrup, Andrew Koenig, P.J. Plauger, Pete Becker... etc and
gave me the same attitude, I'd give it back.

Look, I'm not here to make enemies. The reason I'm here is because I've
read some neat articles by Andrew Koenig in C/C++ User's Journal, had
read some archived posts by him and it looked like a neat place to hang
out.

I'm really not a bad guy. I love C++/Linux/Beer/Lord of the Rings... how
bad can I be? :-)

But if it helps to smooth things out here and keep everyone from
thinking I'm a troll, I apologize to Victor.

Thanks,
KPB
Jul 22 '05 #16
"KPB" <k@w.net> wrote in message news:Yw******************@fe10.lga...
Cy Edmunds wrote:

When you have contributed 5% of what Victor has to this newsgroup perhaps
you will have the credibility to make such statements. That will take you
quite a while. In the meantime I counsel politeness.
So I have to be polite and take his snide shit just because he happens to
have been around a NG longer?

I'm sorry but contribution has nothing to do with this. If this guy were
Bjarne Stroustrup, Andrew Koenig, P.J. Plauger, Pete Becker... etc and
gave me the same attitude, I'd give it back.


Say what you want to PJ. LOL
Look, I'm not here to make enemies. The reason I'm here is because I've
read some neat articles by Andrew Koenig in C/C++ User's Journal, had read
some archived posts by him and it looked like a neat place to hang out.

I'm really not a bad guy. I love C++/Linux/Beer/Lord of the Rings... how
bad can I be? :-)

But if it helps to smooth things out here and keep everyone from thinking
I'm a troll, I apologize to Victor.

Thanks,
KPB


--
Cy
http://home.rochester.rr.com/cyhome/
Jul 22 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: bartek d | last post by:
Hello, Regarding my previous question about a class which is used to store a variable type vector. I tried to be more elaborate on the code. I'd be grateful for your suggestions. Am I going in...
27
by: Jason Heyes | last post by:
To my understanding, std::vector does not use reference counting to avoid the overhead of copying and initialisation. Where can I get a reference counted implementation of std::vector? Thanks.
18
by: Janina Kramer | last post by:
hi ng, i'm working on a multiplayer game for a variable number of players and on the client side, i'm using a std::vector<CPlayer> to store informatik about the players. CPlayer is a class that...
5
by: canned.net | last post by:
I have a class Scene that has several subclasses: World, Vault, etc. I fill a vector with these classes and then cannot go through and delete them. What's the trick to deleting pointers from a...
20
by: Anonymous | last post by:
Is there a non-brute force method of doing this? transform() looked likely but had no predefined function object. std::vector<double> src; std::vector<int> dest; ...
32
by: zl2k | last post by:
hi, c++ user Suppose I constructed a large array and put it in the std::vector in a function and now I want to return it back to where the function is called. I can do like this: ...
6
by: Bobrick | last post by:
Hi. Thanks to everyone who replied to my last post, it turns out it wasn't the line where I was trying to treat the variable in question as an array which was the problem, but the line above. ...
13
by: jubelbrus | last post by:
Hi I'm trying to do the following. #include <vector> #include <boost/thread/mutex.hpp> #include <boost/shared_ptr.hpp> #include <boost/tuple/tuple.hpp> class {
19
by: Daniel Pitts | last post by:
I have std::vector<Base *bases; I'd like to do something like: std::for_each(bases.begin(), bases.end(), operator delete); Is it possible without writing an adapter? Is there a better way? Is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.