Bogdan Maier
Bogdan Maier

Reputation: 683

Type definition issue

i have a stucture:

template <class T> struct Array{
int days;
T * M;
Array( int size ) : days(size), M(new T[size])
{
}
~Array()
{
   delete[] M;
}
};

void currentDay();
void add(int,int,Array &);

and a class:

class Expe {
private:
    int hk;     //HouseKeeping
    int fo;     //Food
    int tr;     //Transport
    int cl;     //Clothing
    int tn;     //TelNet
    int ot;     //Others

 }

Class contructor is :

Expe::Expe() {
this->hk = hk;
this->fo = fo;
this->tr = tr;
this->cl = cl;
this->tn = tn;
this->ot = ot;
}

THE PROBLEM: in main function i can manipulate the structure with objects... using the setObj() function for example but when i try to define my functions in Controller or in Controller.h i get the fallowing error:

..\ListStruc.cpp:28:28: error: 'Array' is not a type
..\ListStruc.cpp: In function 'void add(int, int, int)':
..\ListStruc.cpp:31:4: error: request for member 'M' in 'A', which is of non-class type 'int'

EDIT:

void add(int cant, int tip,Array A){
//Adds to current day the amount to a specific type

A.M[currentDay]; // i try to use this object.
}

Upvotes: 0

Views: 76

Answers (1)

interjay
interjay

Reputation: 110098

This declaration is incorrect:

void add(int,int,Array &);

Since Array is a class template, the add function needs to be a template as well:

template <class T>
void add(int,int,Array<T> &);

Additionally, your definition of the add function takes the parameter by value, while the declaration takes the parameter by reference.

Upvotes: 2

Related Questions