C++ 错误:"<"标记之前应为";"
c++ error: expected ‘;’ before ‘<’ token
所以我在写光线追踪器的同时试图学习c++,当我尝试使用我的makefile(首先生成.o文件,然后链接它们)编译时,我有点纠结于这个错误。完整的错误如下:
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
导致问题的代码是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
我已经检查了包含在这个如matrix.h和matrix_w.h的其他文件,我很确定他们没有丢失任何分号或任何的东西。我甚至尝试编译一切,但t_stack.h文件,它正确构建…知道是什么问题吗?这有点奇怪,因为在我尝试将这些文件与其他代码合并之前,我用更简单的程序做了几次测试,结果都很好……非常感谢你的帮助。谢谢!
stack
和list
,就像标准库中的所有东西一样,在std
命名空间中声明。为了使用它们,您需要将它们限定为std::stack
和std::list
。
同时,不要使用_STACK_H_
这样的保留名称。
您的stack
和list
应该是std::stack
和std::list
。顺便说一下,不要试图在头文件中执行using namespace std
—这是错误的方法。您需要在头文件中包含名称空间。
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 错误:调用"std::vector<:vector<int>>::p ush_back(std::vector<std::__cxx11::basic_string<
- 错误,包括&lt; ctype&gt;在原子上使用C 11
- &lt;&lt;操作员在C 中超载错误
- opencv 2.4.7在iOS错误背景_segm.hpp #include&lt; list&gt;未找到
- '&lt;'''&lt;'''&quot的模板类错误''令牌”
- 在尝试超载&lt;&lt;时链接错误2005和1169操作员
- 错误:没有匹配'运算符<<"在'std::cout
- 过载<<比如cout错误
- 重载& lt; & lt;为什么我得到以下错误
- 重载ostream&时转换错误无效;operator< & lt;
- 重载<<运算符错误C2804:二进制'运算符<<'参数太多
- 编译器错误,包括'<'代币
- 重载& lt; & lt;错误