Reputation: 419
So I am trying to learn c++ while writing a raytracer and I am kind of struggling a bit with this error when I try to compile using my makefile (which first generates the .o files and then links them). The full error is the following:
touch include/ray.h
touch include/material.h
touch include/hit.h
touch include/object.h
touch include/light.h
touch include/scene.h
touch include/sphere.h
touch include/directional_light.h
g++ -c -O -I. raytrace.cpp -o raytrace.o -std=c++0x
g++ -c -O -I. base/scene.cpp -o base/scene.o -std=c++0x
g++ -c -O -I. base/vector.cpp -o base/vector.o -std=c++0x
g++ -c -O -I. base/vertex.cpp -o base/vertex.o -std=c++0x
g++ -c -O -I. base/colour.cpp -o base/colour.o -std=c++0x
g++ -c -O -I. objects/object.cpp -o objects/object.o -std=c++0x
g++ -c -O -I. objects/sphere.cpp -o objects/sphere.o -std=c++0x
g++ -c -O -I. base/material.cpp -o base/material.o -std=c++0x
g++ -c -O -I. base/ray.cpp -o base/ray.o -std=c++0x
g++ -c -O -I. lights/light.cpp -o lights/light.o -std=c++0x
g++ -c -O -I. lights/directional_light.cpp -o lights/directional_light.o -std=c++0x
g++ -c -O -I. base/hit.cpp -o base/hit.o -std=c++0x
g++ -c -O -I. base/matrix.cpp -o base/matrix.o -std=c++0x
touch include/t_stack.h
g++ -c -O -I. t_stack/matrix_w.cpp -o t_stack/matrix_w.o -std=c++0x
touch include/t_stack.h
g++ -c -O -I. t_stack/t_stack.cpp -o t_stack/t_stack.o -std=c++0x
In file included from t_stack/t_stack.cpp:1:
./include/t_stack.h:12: error: expected ‘;’ before ‘<’ token
./include/t_stack.h:13: error: expected ‘;’ before ‘<’ token
The code that is causing the problem is the t_stack.h file:
1 #ifndef _STACK_H_
2 #define _STACK_H_
3
4 #include <stack>
5 #include <list>
6 #include <iostream>
7 #include "include/matrix.h"
8 #include "include/matrix_w.h"
9
10 class T_stack {
11 private:
12 stack<Matrix_w*, list<Matrix_w* > >* m_stack;
13 list<Matrix<double>* >* t_list;
14 public:
15 T_stack();
16 void pop();
17 void push_translation(double tx, double ty, double tz);
18 void push_scaling(double sx, double sy, double sz);
19 int size() const;
20 ~T_stack();
21 };
22
23 #endif
I have already checked the other files that are included in this one such as matrix.h and matrix_w.h and I am pretty sure they are not missing any semicolons or any of that stuff. I even tried compiling everything but the t_stack.h file and it builds correctly... Any ideas what might be the problem? It is a bit weird because before I tried merging these files with the rest of the code I did a couple of tests with simpler programs and it all worked fine... Help is greatly appreciated. Thanks!
Upvotes: 1
Views: 2923
Reputation: 254431
stack
and list
, like just about everything in the standard library, are declared in the std
namespace. In order to use them, you'll need to qualify them as std::stack
and std::list
.
Also, don't use reserved names like _STACK_H_
.
Upvotes: 5
Reputation: 249123
Your stack
and list
should be std::stack
and std::list
. Do not be tempted to do using namespace std
in a header file, by the way--that's the wrong approach. You need to include the namespaces in header files.
Upvotes: 2