不同文件间二维矩阵的c++下标运算符
c++ subscript operator for 2D matrix between different files
我创建了一个2D矩阵的模板类。但下标运算符(LINE13,14,16~36(不能正常工作。
若我标记LINE72~74(dio.cpp(,程序就可以运行了。线路91~93可以工作。
如果线路72~74(dio.cpp(没有标记。复杂故障和IDE引发错误"无功能调用"(BCB5 E2314(
需要你的帮助!
感谢
BR
Evyyos
001 //[mtrx.h]======================================================================
002 class mtrx
003 {
004 private:
005 unsigned int _row;
006 unsigned int _col;
007 T** _m;
008 public:
009 mtrx();
010 mtrx(unsigned int, unsigned int);
011 ~mtrx();
012 ... ...
013 T& operator()(unsigned int row, unsigned int col);
014 T operator()(unsigned int row, unsigned int col) const;
015 ... ...
016 //c++ subscript operator
017 template<class T> inline T&
018 mtrx<T>::operator () (unsigned int row, unsigned int col)
019 {
020 if((row < this->_row) && (col < this->_col)){
021 return this->_m[row][col];
022 }
023 }
024
025 //c++ subscript operator
026 template<class T> inline T
027 //mtrx<T>::operator () (int row, int col) const
028 mtrx<T>::operator () (unsigned int row, unsigned int col) const
029 {
030 //if((row < this->_row) && (col < this->_col)){
031 // return this->_m[row][col];
032 //}
033 if((row < _row) && (col < _col)){
034 return _m[row][col];
035 }
036 }
037 //==============================================================================
038
039 //[dio.h]======================================================================
040 ... ...
041 #include "....includemtrx.h"
042 ... ...
043 unsigned long
044 dio_csv_analysis(
045 const char *ifile_name,
046 double smapling_ratio,
047 char fs,
048 unsigned int nn_selected_mask_size,
049 vector <int> inn_input_mask,
050 vector <int> inn_target_mask,
051 mtrx<double> *inn_input_stat,
052 mtrx<double> *inn_target_stat
053 );
054 ... ...
055 //==============================================================================
056
057 //[dio.cpp]====================================================================
058 ... ...
059 unsigned long
060 dio_csv_analysis(
061 const char *ifile_name,
062 double smapling_ratio,
063 char fs,
064 unsigned int nn_selected_mask_size,
065 vector <int> inn_input_mask,
066 vector <int> inn_target_mask,
067 mtrx<double> *inn_input_stat,
068 mtrx<double> *inn_target_stat
069 )
070 {
071 ... ...
072 inn_input_stat(nn_input_mask_id, NN_INPUT_AVG) = f_item; <<Compile ERR:: all of nonfunction
073 inn_input_stat(nn_input_mask_id, NN_INPUT_MAX) = f_item; <<Compile ERR:: all of nonfunction
074 inn_input_stat(nn_input_mask_id, NN_INPUT_MIN) = f_item; <<Compile ERR:: all of nonfunction
075
076 ... ...
077 //==============================================================================
078
079 //[global.h]======================================================================
080 ... ...
081 #include "dio_csv.h"
082 ... ...
083 //==============================================================================
084
085 //[main.cpp]====================================================================
086 ... ...
087 mtrx<double> nn_input_stat(nn_input_mask_size, 3);
088 mtrx<double> nn_target_stat(nn_target_mask_size, 3);
089 ... ...
090 double m=9,n=5,k=0;
091 nn_input_stat(0,0) = m; <<RUN TIME:: can work normally
092 nn_target_stat(0,0) = n; <<RUN TIME:: can work normally
093 n = nn_target_stat(0,0) - nn_input_stat(0,0); <<RUN TIME:: can work normally
094 ... ...
095 row_count=
096 dio_csv_analysis(
097 dio_csv_file.c_str(),
098 sampling_ratio,
099 ',',
100 nn_selected_mask_size,
101 nn_input_mask,
102 nn_target_mask,
103 &nn_input_stat,
104 &nn_target_stat
105 );
106 ... ...
107 //==============================================================================
mtrx::operator ()
不是下标运算符,是函数调用运算符,调用方式如下:m(x, y)
。
下标运算符为mtrx::operator []
。如果你需要一个二维下标运算符,你需要让第一个下标返回一个代理对象,这个代理对象也实现了下标运算符。当代理被下标时,评估调用所需的所有参数都准备好了。
inn_input_stat
是一个指针。使用CCD_ 5。裸指针不定义运算符(int,int(,因此编译器试图将其解释为函数。
相关文章:
- 为什么比较运算符如此快速
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- 使用C++中的模板和运算符重载执行矩阵运算
- 为什么这个运算符<重载函数对 STL 算法不可见?
- 增量运算符与后缀混淆
- 一个关于在C++中重载布尔运算符的问题
- 运算符C++ "delete []"仅删除 2 个前值
- 模板类无法识别友元运算符
- 我可以使用条件运算符初始化C风格的字符串文字吗
- 关闭||运算符优化
- 通过继承类使用来自不同命名空间的运算符
- C++Cast运算符过载
- 如何使用AngelScript注册SFML Vector2运算符
- 重载元组索引运算符-C++
- 如何使用重载的相等(==)运算符向测试用例添加描述
- 为什么Mat类的两个对象可以在不重载运算符+的情况下添加
- 多个If语句与使用逻辑运算符计算条件的单个语句的比较
- 布尔比较运算符是如何在C++中工作的
- 重载运算符new[]的行为取决于析构函数
- 如何防止clang格式在流运算符调用之间添加换行符<<