【问题标题】:not declared in this scope未在此范围内声明
【发布时间】:2009-11-02 12:25:01
【问题描述】:

我收到一条错误消息

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

这是我的 cpp 文件

#include "DataReader.h"

using namespace std;

vector<Data*> DataReader(String textFile) //line 5 that's giving error
{........}

这是我的头文件

#include <fstream>
#include <iostream>
#include <vector>
#include <string>

#ifndef DATA_H
#define DATA_H
#include "Data.h"
#endif

std::vector<Data*> DataReader(String something);

当我取出字符串参数并对字符串的名称进行硬编码时,它们工作正常。但我需要多次使用这个函数,并且希望能够传入一个字符串作为参数。我传递的字符串是文本文件的名称。我在哪里弄错了吗?我似乎无法弄清楚..我的意思是“字符串”没有在这个范围内声明是什么意思?我正在通过它,我包括 .我的参数有问题??如果您能对此事有所了解,将不胜感激..

院长

【问题讨论】:

    标签: c++ scope


    【解决方案1】:

    字符串应该是小写或std::string

    【讨论】:

      【解决方案2】:

      String 更改为string

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-09-20
        • 2016-08-09
        • 2019-02-17
        • 2021-01-07
        • 2016-10-27
        • 2016-06-03
        • 2014-09-11
        相关资源
        最近更新 更多