0

我正在开发一个 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;
}

文本用户界面.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_ */

文本用户界面.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 */
4

2 回答 2

4

在包含标题之前,您正在使用命名空间。切换它们,否则编译器无法识别此标识符。

#include "TextUserInterface.h"
using namespace view;
于 2013-01-27T20:01:24.463 回答
2

颠倒顺序

#include "TextUserInterface.h"

using namespace view; 

您必须在使用之前引入命名空间。

于 2013-01-27T20:02:59.810 回答