std::vector problems

H

Honestmath

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
 
K

KPB

Honestmath said:
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
 
C

cyrusNew

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) {}
};
 
V

Victor Bazarov

Honestmath said:
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
 
K

KPB

cyrusNew said:
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
 
V

Victor Bazarov

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



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
 
K

KPB

Victor said:
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
 
K

KPB

Victor said:
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
 
C

cyrusNew

Uzytkownik "KPB said:
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 :)
 
V

Victor Bazarov

KPB said:
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
 
K

KPB

Victor said:
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.
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 said:
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?
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
 
V

Victor Bazarov

X-No-archive: yes
KPB said:
[...]
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
 
K

KPB

Victor said:
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 ****
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
 
C

Cy Edmunds

KPB said:
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.


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 **** 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.


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.
 
J

Jonathan Mcdougall

KPB said:
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 ****
you*. Yeah.. that's offensive.

<snip>

May I suggest you two continue this discussion in
private?


Jonathan
 
K

KPB

Cy said:
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
 
C

Cy Edmunds

KPB said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,196
Messages
2,571,036
Members
47,631
Latest member
kukuh

Latest Threads

Top