-3

(*配列構造体を使用する必要があり、動的でなければなりません)

Array構造体をExpeクラス オブジェクトで埋めたい。テンプレートを使用していますが、構造体ヘッダーが作成したテンプレートを認識しません。

構造ヘッダー:

template <class T>;
struct Arr{
    int days;
    T * M;
};
typedef Arr* Array;

構造体 cpp:

void constr(Array &o){
    //Construct of 31*1 Matrix
    o=new Arr;
    o->days = 31;
    o->M = new T[o->days];

大丈夫だと思いますが、エラーが発生します:

..\ListStruc.cpp:26:13: error: expected type-specifier before 'T'
4

2 に答える 2

0

You have to remove the semicolon in the structure declaration. Also, when you create an object of this type, you have to specify the template class name. And you cannot put a pointer into a reference. In fact you can't put anything in a reference, they are constants. Use a pointer instead of reference as the constr function parameter.

于 2012-04-12T13:29:15.547 に答える