我想这样做:
template <typename T>
struct S
{
...
static double something_relevant = 1.5;
};
Run Code Online (Sandbox Code Playgroud)
但我不能因为something_relevant不是整体类型.它不依赖于T,但现有代码依赖于它是静态成员S.
由于S是模板,我不能将定义放在编译文件中.我该如何解决这个问题?
我是C++的新手,在Ubuntu 10.04上使用NetBeans IDE准备作业.我使用g ++作为C++编译器.
错误消息:
build/Debug/GNU-Linux-x86/Maze.o: In function `Maze':
Maze/Maze.cpp:14: undefined reference to `Stack<Coordinate>::Stack()'
Maze/Maze.cpp:14: undefined reference to `Stack<Coordinate>::Stack()'
Maze/Maze.cpp:69: undefined reference to `Stack<Coordinate>::push(Coordinate)'
Maze/Maze.cpp:79: undefined reference to `Stack<Coordinate>::isEmpty()'
Maze/Maze.cpp:87: undefined reference to `Stack<Coordinate>::destroy()'
Run Code Online (Sandbox Code Playgroud)
我的相关代码:
#include "Coordinate.h"
#include "Stack.h"
....
....
/**
* Contains the stack object
*
* @var Stack stack
* @access private
*/
Stack<Coordinate> *stack;
...
...
Run Code Online (Sandbox Code Playgroud)
#include "Maze.h"
...
...
Maze::Maze()
{
// IT SHOWS THAT THE FOLLOWING LINE HAS AN ERROR///
stack = …Run Code Online (Sandbox Code Playgroud)