简体   繁体   English

C ++错误:预期为“;” 在“ <”令牌之前

[英]c++ error: expected ‘;’ before ‘<’ token

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). 因此,我尝试在编写raytracer的同时学习c ++,当我尝试使用makefile进行编译(首先生成.o文件,然后将它们链接)时,我有点为这个错误苦苦挣扎。 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: 导致该问题的代码是t_stack.h文件:

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. 我已经检查了此文件中包含的其他文件,例如matrix.h和matrix_w.h,我很确定它们不会丢失任何分号或任何其他东西。 I even tried compiling everything but the t_stack.h file and it builds correctly... Any ideas what might be the problem? 我什至尝试编译除t_stack.h文件之外的所有文件,并且它可以正确构建...任何想法可能是什么问题? 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! 谢谢!

stack and list , like just about everything in the standard library, are declared in the std namespace. stacklist ,就像标准库中的几乎所有内容一样,都在std名称空间中声明。 In order to use them, you'll need to qualify them as std::stack and std::list . 为了使用它们,您需要将它们限定为std::stackstd::list

Also, don't use reserved names like _STACK_H_ . 另外,请勿使用_STACK_H_类的保留名称

Your stack and list should be std::stack and std::list . 您的stacklist应为std::stackstd::list Do not be tempted to do using namespace std in a header file, by the way--that's the wrong approach. 顺便说一句,不要试图在头文件中using namespace std -这是错误的方法。 You need to include the namespaces in header files. 您需要在头文件中包含名称空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM