C++ 未在此范围内声明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1661007/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
not declared in this scope
提问by user200632
I'm getting an error msg
我收到错误消息
DataReader.h:13: error: 'String' was not declared in this scope
DataReader.cpp:5: error: redefinition of 'std::vector<Data*, std::allocator<Data*> > DataReader'
DataReader.h:13: error: 'std::vector<Data*, std::allocator<Data*> > DataReader' previously declared here
DataReader.cpp:5: error: 'String' was not declared in this scope
this is my cpp file
这是我的 cpp 文件
#include "DataReader.h"
using namespace std;
vector<Data*> DataReader(String textFile) //line 5 that's giving error
{........}
and this my header file
这是我的头文件
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#ifndef DATA_H
#define DATA_H
#include "Data.h"
#endif
std::vector<Data*> DataReader(String something);
they work fine when i take out the string parameter and hard code the name of the string. but i need to use this function several times and would like to be able to pass in a string as a parameter. the string that i'm passing is name of a text file. am i mistaken somewhere? i can't seem to figure it out.. i mean what does it mean 'String' was not declared in this scope?? I am passing it and I included . something wrong with my parameter?? if you can shed some light to this matter, it would be greatly appreciated..
当我取出字符串参数并硬编码字符串的名称时,它们工作正常。但我需要多次使用此函数,并希望能够将字符串作为参数传递。我传递的字符串是文本文件的名称。我在某处弄错了吗?我似乎无法弄清楚..我的意思是“字符串”未在此范围内声明是什么意思?我正在通过它,我包括 . 我的参数有问题??如果您能对此事有所了解,将不胜感激。
Dean
院长
回答by Chris Bednarski
string should be lower case or std::string
字符串应该是小写或 std::string
回答by Danny Whitt
Change String
to string
.
更改String
为string
。