Bru*_*ero 2 c++ data-structures
我正在尝试用C++编写链接队列,但到目前为止我都失败了.我现在创建了2个文件:my main.cpp和box.h. 当我尝试使用我的盒子时,收到以下消息:
说明资源路径位置从'Box*'到非标量类型'Box'的类型转换请求main.cpp/QueueApplication第14行C/C++问题
我的代码如下:
box.h
#ifndef BOX_H_
#define BOX_H_
template<class T>
class Box
{
public:
Box(T value)
{
this->value = value;
this->nextBox = NULL;
}
T getValue()
{
return this->value;
}
void setNext(Box<T> next)
{
this->nextBox = next;
}
private:
T value;
Box<T> nextBox;
};
#endif /* BOX_H_ */
Run Code Online (Sandbox Code Playgroud)
main.cpp中
#include<iostream>
#include "box.h"
using namespace std;
int main(int argc, char** argv)
{
Box<int> newBox = new Box<int>();
cout << "lol";
cin.get();
cin.ignore();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
你们能帮助我吗?
PS:在有人问我为什么不使用stl之前......我在数据结构类中.
删除不重要的东西,我们看到你已经宣布了一个像这样的新类:
template<class T>
class Box
{
T value;
Box<T> nextBox;
};
Run Code Online (Sandbox Code Playgroud)
有多大Box<T>?
明确地
sizeof Box<T> >= sizeof(Box<T>::value) + sizeof(Box<T>::nextBox)
sizeof Box<T> >= sizeof(T) + sizeof(Box<T>)
0 >= sizeof (T)
Run Code Online (Sandbox Code Playgroud)
嗯,哦