类型定义问题
Type definition issue
我有一个结构:
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 &);
和一个类:
class Expe {
private:
int hk; //HouseKeeping
int fo; //Food
int tr; //Transport
int cl; //Clothing
int tn; //TelNet
int ot; //Others
}
类构造器是:
Expe::Expe() {
this->hk = hk;
this->fo = fo;
this->tr = tr;
this->cl = cl;
this->tn = tn;
this->ot = ot;
}
问题:在主函数中,我可以用对象操纵结构......例如,使用 setObj() 函数,但是当我尝试在控制器或 Controller.h 中定义我的函数时,我收到休耕错误:
..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'
编辑:
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.
}
此声明不正确:
void add(int,int,Array &);
由于Array
是一个类模板,因此add
函数也需要是一个模板:
template <class T>
void add(int,int,Array<T> &);
此外,add
函数的定义按值获取参数,而声明按引用获取参数。
相关文章:
- Visual Studio中的函数声明和函数定义问题
- 使用自定义比较函数使用std::sort()对矢量字符串进行排序时出现问题
- Cmake 链接问题:未定义对 Button::mousePressEvent(QGraphicsSceneMouseE
- 如何在标头中声明(或定义)函数的问题
- Xcode 语义问题引用或以前定义的代码
- 我的超类中的模板问题与结构定义
- Arduino:在 loop() 和自定义函数中运行相同的代码时出现问题
- 编译问题:在函数"_start"中:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 将文件复制到自定义位置,存在字符串转换问题
- 在C++中循环访问自定义结构列表的小问题
- 运行veins_inet示例 - 未定义的引用的 Omnet++ 问题
- libssh 问题编译问题未定义的错误
- 在点云库 (PCL) 中使用自定义点类型的问题
- C++ - 对 PCM::getInstance() 的未定义引用问题
- 在 C++ 的自定义运算符中删除与删除[](不同于常见的删除与删除[]问题)
- 用户定义的文本运算符(在原始模式下)存在问题
- 从 C++ 到 Python 的 SWIG:未定义的符号导入问题
- 在内联程序集中定义函数和从 C++ 调用时出现问题
- 在 cout 中将线条表单文件与自定义文本组合时出现问题
- 在Visual Studio代码中包含自定义c++库的问题