Search code examples
c++gcccygwin

Issue with namespace in c++ '<type error> is not a namespace'


I am working on a c++ program and I have made a TextUserInterface class and am trying to call an instance of it inside of the main method. Here is the TextUserInterface.h, TextUserInterface.cpp, and GasStationFinder.cpp(houses main method).

#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 */

Solution

  • You are using the namespace before including the header. Switch them around otherwise the compiler cannot recognize this identifier.

    #include "TextUserInterface.h"
    using namespace view;