473,785 Members | 2,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is wrong with this declaration ?

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
24 1452
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
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
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
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
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
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
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
* 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
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

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

Similar topics

2
2058
by: Sylvain Thenault | last post by:
Hi there ! I've noticed the following problem with python >= 2.3 (actually 2.3.4 and 2.4): syt@musca:test$ python Python 2.3.4 (#2, Sep 24 2004, 08:39:09) on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import parser >>> parser.suite('# -*- coding: IBO-8859-1 -*-')
15
2460
by: M.Siler | last post by:
<HTML> <HEAD> <TITLE></TITLE> <SCRIPT> <!-- var factor_val = new Array(8,7) factor_val = 68.8 factor_val = 55
20
2568
by: Sam | last post by:
Hi I'm learning to code with C++ and wrote some very simple code. I think it's consistent with every rule but always got compiling errors that I don't understand. The code include 5 files as following, delimited by //////: ////////////////pose.h #ifndef pose_h #define pose_h #include "point.h"
11
2234
by: Dart | last post by:
This code is okay: class CSingle { public: static CSingle membs; int MEM_NUM; CSingle(int n) { }
28
3278
by: Madhur | last post by:
Hello what about this nice way to open a file in single line rather than using if and else. #include<stdio.h> void main() { FILE *nd; clrscr(); fopen("c:\\autoexec.bat","r")&&printf("success") || printf("error opeing
9
1663
by: Curious Student | last post by:
Some places till now, I've seen function prototypes within functions instead of in the global declaration space, which I thought was the way. I thought it was <I>only</I>: int myfunction(int, int); int main(void) {
10
2362
by: Sune | last post by:
Hi, previously I used Eclipse CDT for compiling my files just to get started with C and leave C++ behind. Now it's time to get a little more serious so I've moved my files to a new workplace and begun to use GNU Autotools. I'm sorry to say I'm new to gcc as well :( Now I get the most ridiculous compile error which I'm unable to solve. Can someone, please, help me with this? gcc output together with the files mentioned in the gcc error...
7
6279
by: arun_shamli | last post by:
class CDate { public: CDate() {} CDate(const CDate& date) {} }; CDate function1() { CDate date(); return date;
15
9047
by: robert maas, see http://tinyurl.com/uh3t | last post by:
Here's the source: #include <stdio.h> #include <errno.h> main () { char* str = "9999999999"; long long int llin; char* endptr; /* Set by strtoll */ int nch; errno = 0; llin = strtoll(str, &endptr, 10); printf("errno=%d\n", errno);
7
4270
by: mosfet | last post by:
HI, when trying to compile an embedded version of STL called ustl on win32 platform I get the following error : /// Returns the minimum of \p a and \p b template <typename T1, typename T2> inline const T1 min (const T1& a, const T2& b) { return (a < b ? a : b);
0
10330
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10153
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9952
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8976
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.