这个宣言有什么问题? [英] What is wrong with this declaration ?
问题描述
我想声明一个类型的变量(Vector of pairs) - 好的,我知道这个
可以用地图来完成,但我想暂时保持简单。
我在这个代码片段中将变量声明为ff:
#pragma once
#include< string>
#include< utility>
#include< map>
using namespace std;
vector< pair< int,int>> linePairs; //< - 编译器在这里崩溃
编译器错误消息如下:
语法错误:缺少'';'''之前' '<''
''Script :: vector'':缺少存储类或类型说明符
期待''>''终止模板参数 - list,found''>>''
''前面的意外标记''''
任何指针(没有双关语!)非常感激。
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.
推荐答案
Susan Baker写道:
Susan Baker wrote:
vector< pair< ; int,int>> linePairs; //< - 编译器cringes here
vector<pair <int, int>> linePairs ; // <- compiler cringes here
^ ---在这里插入一个空格
vector< pair< int,int> > linePairs;
Mathias
^--- insert a space just here
vector<pair <int, int> > linePairs;
Mathias
这是一个更全面的代码片段:
#pragma一次
#include< string>
#include< utility> ;
#include< map>
使用命名空间std;
class Script
{
private:
字符串名称;
string source_code;
vector< pair< int,int> linePairs; //< - 编译器不喜欢这个
.........
Susan Baker写道:
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:
我想声明一个类型的变量(Vector of pairs) - 好的,我知道这个
可以用地图来完成,但我想暂时保持简单。
我在这个代码片段中将变量声明为ff:
#pragma一次
#include< string>
#include< utility>
#include< map>
使用命名空间std;
vector< pair< int,int> ;> linePairs; //< - 编译器在这里崩溃
编译器错误消息如下:
语法错误:在''<''之前缺少'';'' >''Script :: vector'':缺少存储类或类型说明符
期望''>''终止template-argument-list,找到''>>''
意外'';''之前的标记
任何指针(没有双关语!)都会非常感激。
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.
>
问题是''>>''是一个运营商。你需要添加一个空格:
vector< pair< int,int> > linePairs;
您还需要包含< vector>
The issue is that ''>>'' is an operator. You need to add a space:
vector<pair <int, int> > linePairs ;
You also need to include <vector>
这篇关于这个宣言有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!