我正在研究一个c ++程序,我已经创建了一个TextUserInterface类,并且我试图在main方法中调用它的一个实例。这是TextUserInterface.h,TextUserInterface.cpp和GasStationFinder.cpp(容纳主要方法)。
#include <iostream>
using namespace std;
using namespace view; // compiler is comlaining here saying '<type error>' is not
// a namespace and expected namespace name before ;
#include "TextUserInterface.h"
int main() {
view::TextUserInterface tui;
tui.run();
return 0;
}
TextUserInterface.h
/*
* TextUserInterface.h
*
* Created on: Jan 27, 2013
* Author: Chris
*/
#ifndef TEXTUSERINTERFACE_H_
#define TEXTUSERINTERFACE_H_
namespace view {
class TextUserInterface {
public:
TextUserInterface();
void run();
virtual ~TextUserInterface();
};
} /* namespace view */
#endif /* TEXTUSERINTERFACE_H_ */
TextUserInterface.cpp
/*
* TextUserInterface.cpp
*
* Created on: Jan 27, 2013
* Author: Chris
*/
#include <iostream>
using namespace std;
#include "TextUserInterface.h"
namespace view {
TextUserInterface::TextUserInterface() {
// TODO Auto-generated constructor stub
}
void TextUserInterface::run(){
cout << "Welcome to the Gas Station Finder" << endl;
cout << "" << endl;
cout << "What would you like to query: (m)inimum price, ma(x)imum price,
(p)repay pumps, (t)hreshold price, (l)ist stations, (q)uit?" << endl;
}
TextUserInterface::~TextUserInterface() {
// TODO Auto-generated destructor stub
}
} /* namespace view */
答案 0 :(得分:4)
在包含标头之前,您正在使用命名空间。切换它们,否则编译器无法识别此标识符。
#include "TextUserInterface.h"
using namespace view;
答案 1 :(得分:2)
撤销订单
#include "TextUserInterface.h"
using namespace view;
在使用之前必须引入命名空间。