By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,592 Members | 1,931 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,592 IT Pros & Developers. It's quick & easy.

What is wrong with this declaration ?

P: n/a
Hi,

I want to declare a variable of type (Vector of pairs) - Ok, I know this
can be done using a map, but I want to keep things simple for now.

I have declared the variable as ff in this code snippet:
#pragma once
#include <string>
#include <utility>
#include <map>

using namespace std;

vector<pair <int, int>> linePairs ; // <- compiler cringes here

Compiler err messages are as ff:

syntax error : missing ';' before '<'
'Script::vector' : missing storage-class or type specifiers
expecting '>' to terminate template-argument-list, found '>>'
unexpected token(s) preceding ';'

Any pointers (no pun intended !) would be much appreciated.

Jul 23 '05 #1
Share this Question
Share on Google+
24 Replies


P: n/a
Susan Baker wrote:
vector<pair <int, int>> linePairs ; // <- compiler cringes here

^--- insert a space just here
vector<pair <int, int> > linePairs;
Mathias
Jul 23 '05 #2

P: n/a
This is a "fuller" snippet of code:

#pragma once

#include <string>
#include <utility>
#include <map>

using namespace std;

class Script
{
private:
string name ;
string source_code ;
vector< pair <int, int> linePairs; // <- compiler dosen't like this

.........

Susan Baker wrote:
Hi,

I want to declare a variable of type (Vector of pairs) - Ok, I know this
can be done using a map, but I want to keep things simple for now.

I have declared the variable as ff in this code snippet:
#pragma once
#include <string>
#include <utility>
#include <map>

using namespace std;

vector<pair <int, int>> linePairs ; // <- compiler cringes here

Compiler err messages are as ff:

syntax error : missing ';' before '<'
'Script::vector' : missing storage-class or type specifiers
expecting '>' to terminate template-argument-list, found '>>'
unexpected token(s) preceding ';'

Any pointers (no pun intended !) would be much appreciated.


Jul 23 '05 #3

P: n/a
The issue is that '>>' is an operator. You need to add a space:
vector<pair <int, int> > linePairs ;
You also need to include <vector>

Jul 23 '05 #4

P: n/a
Hi Mathias,

Thanks for the tip - unfortunately, I tried it and still no joy...

Mathias Waack wrote:
Susan Baker wrote:

vector<pair <int, int>> linePairs ; // <- compiler cringes here


^--- insert a space just here
vector<pair <int, int> > linePairs;
Mathias


Jul 23 '05 #5

P: n/a
Susan Baker <sb****@no.spam.net> schrieb:
vector<pair <int, int>> linePairs ; // <- compiler cringes here


use

vector<pair <int,int> > linePairs;
^
this space is relevant

T.M.
Jul 23 '05 #6

P: n/a
Looks like Mathias didn't point to the exact position. Just break your >>
into >[space]> where [space] means what you get when you hit the space bar.

ben

"Susan Baker" <sb****@no.spam.net> wrote in message
news:da**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
Hi Mathias,

Thanks for the tip - unfortunately, I tried it and still no joy...

Mathias Waack wrote:
Susan Baker wrote:

vector<pair <int, int>> linePairs ; // <- compiler cringes here


^--- insert a space just here
vector<pair <int, int> > linePairs;
Mathias

Jul 23 '05 #7

P: n/a
Nope, still not compiling ... (thanks anyway)

Torsten Mueller wrote:
Susan Baker <sb****@no.spam.net> schrieb:

vector<pair <int, int>> linePairs ; // <- compiler cringes here

use

vector<pair <int,int> > linePairs;
^
this space is relevant

T.M.


Jul 23 '05 #8

P: n/a
* Susan Baker:
[top-posting]
Please don't top-post in this group, see the FAQ, corrected.
* Susan Baker:

#pragma once
#include <string>
#include <utility>
#include <map>
Needs to #include <vector> here.

using namespace std;

vector<pair <int, int>> linePairs ; // <- compiler cringes here


^ Needs an extra space here.

This is a "fuller" snippet of code:

#pragma once

#include <string>
#include <utility>
#include <map>
Needs to #include <vector> here.

using namespace std;

class Script
{
private:
string name ;
string source_code ;
vector< pair <int, int> linePairs; // <- compiler dosen't like this


^ Needs a right angle bracket '>' here.

Btw., if this is a header file then it's not a good idea to have
'using namespace std;' there. If it's an implementation file then
it's OK. Reason: you don't want to force all the names in the std
namespace on clients of the header file.

Also, be aware that '#pragma once' is a non-standard language extension,
although a very common one.

In standard C++ you'd use a header file guard, like

#ifndef SCRIPT_H
#define SCRIPT_H
// ... Contents of header file [script.h] here.
#endif

and many/most compilers recognize this pattern so that they can optimize
their file handling (subsequently they'll avoid opening this file).

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #9

P: n/a
Nope, still not compiling ... (thanks anyway)

Torsten Mueller wrote:


All the posts that are trying to point where you should have a space assume
your newsreader settings are the same as theirs.
Almost all of them are pointing at the wrong place, yet they all mean the
same.

vector<pair <int, int>> linePairs ; // Your code
vector<pair <int, int> > linePairs ; // Note the space after ...int> > ...

Because >>, (no space), means something else so you must add the space so
the compiler doesn't get confused.

Simon
Jul 23 '05 #10

P: n/a


Alf P. Steinbach wrote:
* Susan Baker:
[top-posting]

Please don't top-post in this group, see the FAQ, corrected.
* Susan Baker:
#pragma once
#include <string>
#include <utility>
#include <map>

Needs to #include <vector> here.

using namespace std;

vector<pair <int, int>> linePairs ; // <- compiler cringes here

^ Needs an extra space here.
This is a "fuller" snippet of code:

#pragma once

#include <string>
#include <utility>
#include <map>

Needs to #include <vector> here.
using namespace std;

class Script
{
private:
string name ;
string source_code ;
vector< pair <int, int> linePairs; // <- compiler dosen't like this

^ Needs a right angle bracket '>' here.

Btw., if this is a header file then it's not a good idea to have
'using namespace std;' there. If it's an implementation file then
it's OK. Reason: you don't want to force all the names in the std
namespace on clients of the header file.

Also, be aware that '#pragma once' is a non-standard language extension,
although a very common one.

In standard C++ you'd use a header file guard, like

#ifndef SCRIPT_H
#define SCRIPT_H
// ... Contents of header file [script.h] here.
#endif

and many/most compilers recognize this pattern so that they can optimize
their file handling (subsequently they'll avoid opening this file).


Many thanks Alf - it was the missing header file "who dunnit". It's
always the simplest things that get overlooked - many thanks once again.

Jul 23 '05 #11

P: n/a
Susan Baker wrote:

Susan, *please* don't top-post - you've already been
asked politely once.

[rearranged]
Torsten Mueller wrote:
Susan Baker <sb****@no.spam.net> schrieb:

vector<pair <int, int>> linePairs ; // <- compiler cringes here

use

vector<pair <int,int> > linePairs;
^
this space is relevant

Nope, still not compiling ... (thanks anyway)


Why is it not compiling? What does the compiler say? What
code exactly doesn't compile?

It's generally a very good idea to include a *complete* (minimal,
potentially compilable) program - just cut and paste your code.
That way we can reproduce your problem and help you to solve it.

Help us to help you :-)

FWIW, this (complete) program compiles fine for me:

// start test.cpp

#include <utility>
#include <vector>

int main()
{
std::vector<std::pair<int,int> > linePairs;
return 0;
}

// end test.cpp

Regards,

--
Lionel B

Jul 23 '05 #12

P: n/a


Lionel B wrote:
Susan Baker wrote:

Susan, *please* don't top-post - you've already been
asked politely once.

[rearranged]

Torsten Mueller wrote:

Susan Baker <sb****@no.spam.net> schrieb:

vector<pair <int, int>> linePairs ; // <- compiler cringes here
use

vector<pair <int,int> > linePairs;
^
this space is relevant


Nope, still not compiling ... (thanks anyway)

Why is it not compiling? What does the compiler say? What
code exactly doesn't compile?

It's generally a very good idea to include a *complete* (minimal,
potentially compilable) program - just cut and paste your code.
That way we can reproduce your problem and help you to solve it.

Help us to help you :-)

FWIW, this (complete) program compiles fine for me:

// start test.cpp

#include <utility>
#include <vector>

int main()
{
std::vector<std::pair<int,int> > linePairs;
return 0;
}

// end test.cpp

Regards,


Thanks Lionel, it was an emabarassingly simple case of me forgetting to
#include <vector>, as pointed out by Alf. I'm afraid the templated
parameters were a bit of a red herring.

PS: I did not top post since Alf alerted me to this ng's netiquette.
please check the posting times.

Jul 23 '05 #13

P: n/a
"Simon" <sp********@example.com> schrieb:
All the posts that are trying to point where you should have a space
assume your newsreader settings are the same as theirs.


No, surely not. But using a monospace font rather than a proportional
font should be a rule (!) while reading news, especially in a news
group handling a programming language. However, Outlook people tend to
forget that there has been an outer world before.

T.M.
Jul 23 '05 #14

P: n/a
>
All the posts that are trying to point where you should have a space
assume your newsreader settings are the same as theirs.
No, surely not. But using a monospace font rather than a proportional
font should be a rule (!) while reading news, especially in a news
group handling a programming language. However, Outlook people tend to
forget that there has been an outer world before.


So what are you saying?
Because my settings are not moonscape I am a new plague to the programming
world?

Is using a computer forgetting that their was an outer world?

I accept your settings, and you should accept mine.

T.M.


Simon
Jul 23 '05 #15

P: n/a
Because my settings are not moonscape I am a new plague to the programming


Sorry, "monospace", this outlook spell checker is a real pain. I only wish
the outer world would teach me how to type again.

Simon
Jul 23 '05 #16

P: n/a
Susan Baker wrote:
Lionel B wrote:
/.../
It's generally a very good idea to include a *complete* (minimal,
potentially compilable) program - just cut and paste your code.
That way we can reproduce your problem and help you to solve it.


/.../
Thanks Lionel, it was an emabarassingly simple case of me forgetting
to #include <vector>, as pointed out by Alf. I'm afraid the templated
parameters were a bit of a red herring.
That demonstrates rather nicely the point I was making of posting real
complete code - if you had done so originally your error would have been
spotted straight away.
PS: I did not top post since Alf alerted me to this ng's netiquette.
please check the posting times.


Yes, our mails crossed in the post...

Good luck,

--
Lionel B

Jul 23 '05 #17

P: n/a
"Simon" <sp********@example.com> schrieb:
All the posts that are trying to point where you should have a
space assume your newsreader settings are the same as theirs.
No, surely not. But using a monospace font rather than a
proportional font should be a rule (!) while reading news,
especially in a news group handling a programming language.
However, Outlook people tend to forget that there has been an
outer world before.


So what are you saying? Because my settings are not moonscape I am a
new plague to the programming world?


You can name your own as you want.
Is using a computer forgetting that their was an outer world?
I tried to relativate your opinion, most of the readers see wrong
positions pointed to by my pointer. Indeed most of the Outlook Express
users will have wrong positions because they never did setup a
monospace font using still the default proportional one. I don't know
*any* other news reader using a proportional font by default.
I accept your settings, and you should accept mine.


I accept whatever software you use and whatever you configure (or
not). But using a proportional font in a news group is *your* own home
made problem, not mine.

T.M.
Jul 23 '05 #18

P: n/a
"Simon" <sp********@example.com> write:
All the posts that are trying to point where you should have a
space assume your newsreader settings are the same as theirs.
No, surely not. But using a monospace font rather than a
proportional font should be a rule (!) while reading news,
especially in a news group handling a programming language.
However, Outlook people tend to forget that there has been an
outer world before.


So what are you saying? Because my settings are not moonscape I am a
new plague to the programming world?


You can name yourself as you want.
Is using a computer forgetting that their was an outer world?
I tried to relativate your opinion, most of the readers see wrong
positions pointed to by my pointer. Indeed most of the Outlook Express
users will have wrong positions because they never did configure a
monospace font. So they use still the default proportional font. I
don't know *any* other news reader using a proportional font by
default.
I accept your settings, and you should accept mine.


I accept whatever software you use and whatever you configure (or
not). But using a proportional font in a news group is *your* own home
made problem, not mine.

T.M.

BTW: You could configure at least a charset.
Jul 23 '05 #19

P: n/a
>
I tried to relativate your opinion, most of the readers see wrong
positions pointed to by my pointer. Indeed most of the Outlook Express
users will have wrong positions because they never did configure a
monospace font. So they use still the default proportional font. I
don't know *any* other news reader using a proportional font by
default.
It may be so, but an easy way around is to simply not assume that the whole
world is right, (monospace).
And use a simple alternative.
Computers have evolved enough to allow different fonts, assuming that we all
use the same as you is simply not the answer.
I accept your settings, and you should accept mine.


I accept whatever software you use and whatever you configure (or
not). But using a proportional font in a news group is *your* own home
made problem, not mine.


What a great attitude to have around the internet.
"It's my way, and any other way is your problem"

T.M.

BTW: You could configure at least a charset.


Why on earth would I do that?

Simon
Jul 23 '05 #20

P: n/a
"Simon" <sp********@example.com> schrieb:
BTW: You could configure at least a charset.


Why on earth would I do that?


I said "You could". Of course you will not, I know.

T.M.
Jul 23 '05 #21

P: n/a
> BTW: You could configure at least a charset.
Why on earth would I do that?


I said "You could". Of course you will not, I know.


And I said, (amongst other things), why would I want to do that?

T.M.


Simon
Jul 23 '05 #22

P: n/a
Susan Baker wrote:
This is a "fuller" snippet of code:

#pragma once

#include <string>
#include <utility>
#include <map>

using namespace std;

class Script
{
private:
string name ;
string source_code ;
vector< pair <int, int> linePairs; // <- compiler dosen't like this
(a) don't top-post
(b) the closing angle bracket is missing.

........

Jul 23 '05 #23

P: n/a
Torsten Mueller <de******@shared-files.de> wrote in
news:u3***********@fastmail.fm:
Is using a computer forgetting that their was an outer world?


I tried to relativate your opinion, most of the readers see wrong
positions pointed to by my pointer. Indeed most of the Outlook Express
users will have wrong positions because they never did setup a
monospace font using still the default proportional one. I don't know
*any* other news reader using a proportional font by default.


Actually XNews defaults to a proportional font when reading (but not when
writing, go figure...). However it does have a button to click to change
to a non-proportional font at will...
Jul 23 '05 #24

P: n/a
i have to admit monospace makes reading a lot tiring. Even Bjarne doesn't
use monospace fonts in his book.

ben
Jul 23 '05 #25

This discussion thread is closed

Replies have been disabled for this discussion.