I had a perfectly working project in Qt and I had to add an external library (*.h and *.cpp) to continue working. However, after adding those files to the project I suddenly have 48 errors and they start with the problem with a namespace...
Here is my .pro file:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ean
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
IntervalArithmetic.cpp
HEADERS += mainwindow.h \
IntervalArithmetic.h
FORMS += mainwindow.ui
QMAKE_CXXFLAGS += -std=c++11
LIBS += -lmpfr
LIBS += -lgmp
Here is the beginning of my *.h file added:
#ifndef INTERVALARITHMETIC_H_
#define INTERVALARITHMETIC_H_
#include <iostream>
#include <string>
#include <sstream>
#include <exception>
#include <fenv.h>
#include <stdlib.h>
#include <stdint.h>
#include <mpfr.h>
using namespace std;
namespace intervalarth
{
struct interval
{
long double a, b;
};
class IntervalArithmetic
{
public:
IntervalArithmetic();
...
And here is the beginning of the corresponding *.cpp file:
#include "IntervalArithmetic.h"
#include <sstream>
#include <iomanip>
#include <stdexcept>
#include <cfenv>
#include <cstdlib>
#include <cstdint>
#include <climits>
#include <cmath>
#include "mpfr.h"
using namespace std;
using namespace IntervalArithmetic;
...
errors can be seen on this picture:
Could you please help me?
Your namespace is called namespace intervalarth
, but you're using namespace IntervalArithmetic;
which is not a namespace-name, as stated in the first error on the screenshot above.
You must unify the namespace-name between *.cpp and *.h files.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.