[英]c++ class not declared in scope - called from main
been stuck for quite a while now.现在被困了很长一段时间。 Any help would be much appreciated.任何帮助将非常感激。
FlexStringDemo.cpp - main FlexStringDemo.cpp - 主要
#include "FlexString.h"
#include <iostream>
using namespace std;
int main(){
FlexString inputOne;
return 0;
}
FlexString.h弹性字符串.h
#ifndef FLEXSTRING_H
#define FLEXSTRING_H
#include "LinkedList.h"
namespace linkedList{
class FlexString{
public:
FlexString();
FlexString(std::string input);
private:
LinkedList *list;
std::string data;
};
}
#endif
FlexString.cpp弹性字符串.cpp
#include "FlexString.h"
#include <iostream>
namespace linkedList{
FlexString::FlexString(){
list = new LinkedList();
}
FlexString::FlexString(string input){
list = new LinkedList();
}
}
I get this error message:我收到此错误消息:
FlexStringDemo.cpp: In function ‘int main()’:
FlexStringDemo.cpp:14:2: error: 'FlexString' was not declared in this scope FlexString inputOne; FlexStringDemo.cpp:14:2: 错误: 'FlexString' 未在此范围内声明 FlexString inputOne; ^ FlexStringDemo.cpp:14:2: note: suggested alternative: In file included from FlexStringDemo.cpp:1:0: FlexString.h:7:7: note: 'linkedList::FlexString' class FlexString{ ^ FlexStringDemo.cpp:14:2:注意:建议的替代方案:在 FlexStringDemo.cpp 中包含的文件中:1:0: FlexString.h:7:7:注意:'linkedList::FlexString' class FlexString{
No idea why i cant create a FlexString object as i have included the header file.不知道为什么我不能创建一个 FlexString 对象,因为我已经包含了头文件。 Thanks in advance提前致谢
FlexString
belongs to the namespace linkedList
. FlexString
属于命名空间linkedList
。
You have to use scope resolution to access the class, like this您必须使用范围解析来访问该类,如下所示
linkedList::FlexString inputOne;
Or the using
keyword to omit the namespace或者using
关键字省略命名空间
using namespace linkedList;
Though I recommend against the latter.虽然我建议反对后者。 Writing the namespace explicity is best.明确地编写命名空间是最好的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.