Mar 8, 2017 at 6:14am UTC
My .cpp file shows me a bug, and it says a nested namespace should be used, but I don't understand why and how.
Here is the error message and the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Error message
mingw32-g++.exe -Weffc++ -Wfatal-errors -Wextra -Wall -std=c++11 -pg -g -c
"C:\Users\k\Desktop\CMPT 135\Assignments\Assignment4\test.cpp" -o
"C:\Users\k\Desktop\CMPT 135\Assignments\Assignment4\test.o"
C:\Users\k\Desktop\CMPT 135\Assignments\Assignment4\test.cpp:8:7: error: expected nested
name-specifier before 'namespace'
using namespace std;
^
compilation terminated due to -Wfatal-errors.
Process terminated with status 1 (0 minute(s), 1 second(s))
1 error(s), 0 warning(s) (0 minute(s), 1 second(s))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#include <iostream>
#include <vector>
#include <string>
#include "A.h"
using namespace std;
int main(){
A use; // A is the name of class in A.h file
vector<string> user_Input;
for (int i = 0; i < 3; ++i)
{
cin >> use.out_of(user_Input[i]);
}
use.print(); // print questions, scores, and answers
return 0;
}
Last edited on Mar 8, 2017 at 5:26pm UTC
Mar 8, 2017 at 6:31am UTC
The error is a "A.h". Probably missing }; at the end of the class.
Mar 8, 2017 at 4:37pm UTC
No, I checked A.h, and I have my }; at the end of the class.
Mar 8, 2017 at 4:50pm UTC
The error is in A.h, show A.h
Also, the line numbers in the error message do not correspond with the code you've posted.
Mar 8, 2017 at 6:51pm UTC
I solved the problem, I needed to include an extra namespace for all my .h files, and then include that namespace in my .cpp file like this:
using namespace test;