Reputation: 101
I have two files, homework1.cc
and homework1.h
.
The top of homework1.cc
is
#include <iostream>
#include <fstream>
#include <cstring>
#include <GL/glut.h>
#include "homework1.h"
using namespace std;
and the top of in homework1.h
is
#ifndef _rt_H
#define _rt_H
#include <cmath>
#include <vector>
#include <list>
#include <GL/glut.h>
using namespace std;
This is where I use list
in homework1.h
class surTriangle
{
float x;
float y;
float z;
list <int> surTriangles;
bool compareVertex(Vector3f anotherVec)
{
if(anotherVec[0] == x && anotherVec[1] == y && anotherVec[2] == z)
return true;
return false;
}
}
When I attempt to compile homework.cc
, the compiler reports
homework1.cc:8: error: expected unqualified-id before ‘using’
However when I delete #include <list>
or the third piece of code above it compiles successfully.
Would you please help me to find out what's the problem is?
Upvotes: 2
Views: 4832
Reputation: 143279
You need a semicolon after class declaration. (the last line of the class fragment of homework1.h
). Otherwise using is interpreted as identifier as in
class X {
} x;
Upvotes: 5
Reputation: 385385
You forgot ;
at the end of your class definition.
When debugging parse errors, it's useful to consider how the preprocessor works; in your mind (or with gcc -E
if you want to actually view it properly) imagine what the code looks like after #include
directives have been resolved.
You'd then see that the error falls directly after your class definition, which narrows things down tremendously. The error says that using
is "unexpected", which typically indicates an issue terminating/concluding the previous statement. This leads to spotting the missing semicolon, which is a classic typo.
Upvotes: 3