Connecting Tech Pros Worldwide Forums | Help | Site Map

What is wrong with this declaration ?

Susan Baker
Guest
 
Posts: n/a
#1: Jul 23 '05
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.


Mathias Waack
Guest
 
Posts: n/a
#2: Jul 23 '05

re: What is wrong with this declaration ?


Susan Baker wrote:
[color=blue]
> vector<pair <int, int>> linePairs ; // <- compiler cringes here[/color]
^--- insert a space just here
vector<pair <int, int> > linePairs;


Mathias
Susan Baker
Guest
 
Posts: n/a
#3: Jul 23 '05

re: What is wrong with this declaration ?


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:
[color=blue]
> 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.
>[/color]

titancipher
Guest
 
Posts: n/a
#4: Jul 23 '05

re: What is wrong with this declaration ?


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

Susan Baker
Guest
 
Posts: n/a
#5: Jul 23 '05

re: What is wrong with this declaration ?


Hi Mathias,

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

Mathias Waack wrote:
[color=blue]
> Susan Baker wrote:
>
>[color=green]
>>vector<pair <int, int>> linePairs ; // <- compiler cringes here[/color]
>
> ^--- insert a space just here
> vector<pair <int, int> > linePairs;
>
>
> Mathias[/color]

Torsten Mueller
Guest
 
Posts: n/a
#6: Jul 23 '05

re: What is wrong with this declaration ?


Susan Baker <sbaker@no.spam.net> schrieb:
[color=blue]
> vector<pair <int, int>> linePairs ; // <- compiler cringes here[/color]

use

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

T.M.
benben
Guest
 
Posts: n/a
#7: Jul 23 '05

re: What is wrong with this declaration ?


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" <sbaker@no.spam.net> wrote in message
news:dadmr7$5uj$2@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...[color=blue]
> Hi Mathias,
>
> Thanks for the tip - unfortunately, I tried it and still no joy...
>
> Mathias Waack wrote:
>[color=green]
> > Susan Baker wrote:
> >
> >[color=darkred]
> >>vector<pair <int, int>> linePairs ; // <- compiler cringes here[/color]
> >
> > ^--- insert a space just here
> > vector<pair <int, int> > linePairs;
> >
> >
> > Mathias[/color]
>[/color]


Susan Baker
Guest
 
Posts: n/a
#8: Jul 23 '05

re: What is wrong with this declaration ?


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

Torsten Mueller wrote:
[color=blue]
> Susan Baker <sbaker@no.spam.net> schrieb:
>
>[color=green]
>>vector<pair <int, int>> linePairs ; // <- compiler cringes here[/color]
>
>
> use
>
> vector<pair <int,int> > linePairs;
> ^
> this space is relevant
>
> T.M.[/color]

Alf P. Steinbach
Guest
 
Posts: n/a
#9: Jul 23 '05

re: What is wrong with this declaration ?


* Susan Baker:[color=blue]
> [top-posting][/color]

Please don't top-post in this group, see the FAQ, corrected.


* Susan Baker:[color=blue][color=green]
> >
> > #pragma once
> > #include <string>
> > #include <utility>
> > #include <map>[/color][/color]

Needs to #include <vector> here.
[color=blue][color=green]
> >
> > using namespace std;
> >
> > vector<pair <int, int>> linePairs ; // <- compiler cringes here[/color][/color]

^ Needs an extra space here.

[color=blue]
> This is a "fuller" snippet of code:
>
> #pragma once
>
> #include <string>
> #include <utility>
> #include <map>[/color]

Needs to #include <vector> here.

[color=blue]
> using namespace std;
>
> class Script
> {
> private:
> string name ;
> string source_code ;
> vector< pair <int, int> linePairs; // <- compiler dosen't like this[/color]

^ 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?
Simon
Guest
 
Posts: n/a
#10: Jul 23 '05

re: What is wrong with this declaration ?


[color=blue]
> Nope, still not compiling ... (thanks anyway)
>
> Torsten Mueller wrote:
>[/color]

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


Susan Baker
Guest
 
Posts: n/a
#11: Jul 23 '05

re: What is wrong with this declaration ?




Alf P. Steinbach wrote:
[color=blue]
> * Susan Baker:
>[color=green]
>>[top-posting][/color]
>
>
> Please don't top-post in this group, see the FAQ, corrected.
>
>
> * Susan Baker:
>[color=green][color=darkred]
>>>#pragma once
>>>#include <string>
>>>#include <utility>
>>>#include <map>[/color][/color]
>
>
> Needs to #include <vector> here.
>
>[color=green][color=darkred]
>>>using namespace std;
>>>
>>>vector<pair <int, int>> linePairs ; // <- compiler cringes here[/color][/color]
>
>
> ^ Needs an extra space here.
>
>
>[color=green]
>>This is a "fuller" snippet of code:
>>
>>#pragma once
>>
>>#include <string>
>>#include <utility>
>>#include <map>[/color]
>
>
> Needs to #include <vector> here.
>
>
>[color=green]
>>using namespace std;
>>
>>class Script
>>{
>>private:
>> string name ;
>> string source_code ;
>> vector< pair <int, int> linePairs; // <- compiler dosen't like this[/color]
>
>
> ^ 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).
>[/color]

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

Lionel B
Guest
 
Posts: n/a
#12: Jul 23 '05

re: What is wrong with this declaration ?


Susan Baker wrote:

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

[rearranged]
[color=blue]
> Torsten Mueller wrote:
>[color=green]
>> Susan Baker <sbaker@no.spam.net> schrieb:
>>
>>[color=darkred]
>>> vector<pair <int, int>> linePairs ; // <- compiler cringes here[/color]
>>
>>
>> use
>>
>> vector<pair <int,int> > linePairs;
>> ^
>> this space is relevant
>>[/color]
> Nope, still not compiling ... (thanks anyway)[/color]

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

Susan Baker
Guest
 
Posts: n/a
#13: Jul 23 '05

re: What is wrong with this declaration ?




Lionel B wrote:
[color=blue]
> Susan Baker wrote:
>
> Susan, *please* don't top-post - you've already been
> asked politely once.
>
> [rearranged]
>
>[color=green]
>>Torsten Mueller wrote:
>>
>>[color=darkred]
>>>Susan Baker <sbaker@no.spam.net> schrieb:
>>>
>>>
>>>
>>>>vector<pair <int, int>> linePairs ; // <- compiler cringes here
>>>
>>>
>>>use
>>>
>>> vector<pair <int,int> > linePairs;
>>> ^
>>> this space is relevant
>>>[/color]
>>
>>Nope, still not compiling ... (thanks anyway)[/color]
>
>
> 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,
>[/color]

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.

Torsten Mueller
Guest
 
Posts: n/a
#14: Jul 23 '05

re: What is wrong with this declaration ?


"Simon" <spambucket@example.com> schrieb:
[color=blue]
> All the posts that are trying to point where you should have a space
> assume your newsreader settings are the same as theirs.[/color]

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.
Simon
Guest
 
Posts: n/a
#15: Jul 23 '05

re: What is wrong with this declaration ?


>[color=blue][color=green]
>> All the posts that are trying to point where you should have a space
>> assume your newsreader settings are the same as theirs.[/color]
>
> 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.[/color]

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.
[color=blue]
>
> T.M.[/color]

Simon


Simon
Guest
 
Posts: n/a
#16: Jul 23 '05

re: What is wrong with this declaration ?


[color=blue]
> Because my settings are not moonscape I am a new plague to the programming[/color]

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

Simon


Lionel B
Guest
 
Posts: n/a
#17: Jul 23 '05

re: What is wrong with this declaration ?


Susan Baker wrote:[color=blue]
> Lionel B wrote:[/color]

/.../
[color=blue][color=green]
>> 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.[/color][/color]

/.../
[color=blue]
> 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.[/color]

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.
[color=blue]
> PS: I did not top post since Alf alerted me to this ng's netiquette.
> please check the posting times.[/color]

Yes, our mails crossed in the post...

Good luck,

--
Lionel B

Torsten Mueller
Guest
 
Posts: n/a
#18: Jul 23 '05

re: What is wrong with this declaration ?


"Simon" <spambucket@example.com> schrieb:
[color=blue][color=green][color=darkred]
> > > All the posts that are trying to point where you should have a
> > > space assume your newsreader settings are the same as theirs.[/color]
> >
> > 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.[/color]
>
> So what are you saying? Because my settings are not moonscape I am a
> new plague to the programming world?[/color]

You can name your own as you want.
[color=blue]
> Is using a computer forgetting that their was an outer world?[/color]

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.
[color=blue]
> I accept your settings, and you should accept mine.[/color]

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.
Torsten Mueller
Guest
 
Posts: n/a
#19: Jul 23 '05

re: What is wrong with this declaration ?


"Simon" <spambucket@example.com> write:
[color=blue][color=green][color=darkred]
> > > All the posts that are trying to point where you should have a
> > > space assume your newsreader settings are the same as theirs.[/color]
> >
> > 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.[/color]
>
> So what are you saying? Because my settings are not moonscape I am a
> new plague to the programming world?[/color]

You can name yourself as you want.
[color=blue]
> Is using a computer forgetting that their was an outer world?[/color]

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.
[color=blue]
> I accept your settings, and you should accept mine.[/color]

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.
Simon
Guest
 
Posts: n/a
#20: Jul 23 '05

re: What is wrong with this declaration ?


>[color=blue]
> 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.[/color]

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.
[color=blue][color=green]
>> I accept your settings, and you should accept mine.[/color]
>
> 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.[/color]

What a great attitude to have around the internet.
"It's my way, and any other way is your problem"
[color=blue]
>
> T.M.
>
> BTW: You could configure at least a charset.[/color]

Why on earth would I do that?

Simon


Torsten Mueller
Guest
 
Posts: n/a
#21: Jul 23 '05

re: What is wrong with this declaration ?


"Simon" <spambucket@example.com> schrieb:
[color=blue][color=green]
> > BTW: You could configure at least a charset.[/color]
>
> Why on earth would I do that?[/color]

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

T.M.
Simon
Guest
 
Posts: n/a
#22: Jul 23 '05

re: What is wrong with this declaration ?


[color=blue]
>[color=green][color=darkred]
>> > BTW: You could configure at least a charset.[/color]
>>
>> Why on earth would I do that?[/color]
>
> I said "You could". Of course you will not, I know.[/color]

And I said, (amongst other things), why would I want to do that?
[color=blue]
>
> T.M.[/color]

Simon


Victor Bazarov
Guest
 
Posts: n/a
#23: Jul 23 '05

re: What is wrong with this declaration ?


Susan Baker wrote:[color=blue]
> 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[/color]

(a) don't top-post
(b) the closing angle bracket is missing.
[color=blue]
>
> ........
>[/color]
Andre Kostur
Guest
 
Posts: n/a
#24: Jul 23 '05

re: What is wrong with this declaration ?


Torsten Mueller <dev-null@shared-files.de> wrote in
news:u3bqta351.fsf@fastmail.fm:
[color=blue][color=green]
>> Is using a computer forgetting that their was an outer world?[/color]
>
> 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.[/color]

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...
benben
Guest
 
Posts: n/a
#25: Jul 23 '05

re: What is wrong with this declaration ?


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

ben


Closed Thread