【发布时间】:2010-01-07 16:06:36
【问题描述】:
基本上,我正在尝试编译一个模板类,该类旨在表示一个用于将多项式相加的表格。因此,表需要可以为空。
这就是我试图代表http://www.mathsisfun.com/algebra/polynomials-adding-subtracting.html的那种东西。
这就是要做到这一点的模板:
template <class T> class TableWithBlanks : public Table<T> {
public:
TableWithBlanks( const int width, const int height ) : w(width), h(height), table_contents( new t_node[width][height]
{
table_contents = new t_node[width][height];
// Go through all the values and blank them.
for( int i = 0; i < w; i++)
{
for( int a = 0; a < h; a++)
{
table_contents[i][a].value_ptr = NULL;
}
}
}
void set_value( const int width, const int height, const T* table_value_ptr)
{
if( width <= w && height <= h )
{
table_contents[w][h] = table_value_ptr;
}
}
T* get_value( const int width, const int height)
{
if( width <= w && height <= h )
{
return table_contents[width][height];
}
}
private:
typedef struct node {
T* value_ptr;
} t_node;
t_node** table_contents;
int w;
int h;
};
这是我得到的错误:
[C++ 错误] TableWithBlanks.h(16): E2034 无法转换 'TableWithBlanks::node ( *)[1]' 到 'TableWithBlanks::node * *'
PolynomialNode 类是一个链表类,链表中的每个节点都表示一个简单多项式中的项 - 我不需要详细说明。
【问题讨论】:
标签: c++