用c++写一个矩阵类的构造函数,使得其可以用类似以下语句声明并初始化 Matrix m = {{1,2,3},{4,5,6}}; 50
1个回答
展开全部
#include <iostream>
double** matrix_init( const int row, const int col )
{
double** mat = new double*[row];
for ( int i = 0; i < row; i++)
{
mat[i] = new double[col];
}
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++) mat[i][j] = i*row + j + 1.0;
}
return mat;
}
void matrix_print( double** matrix, const int row, const int col )
{
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++) std::cout << matrix[i][j] << " " << std::flush;
std::cout << std::endl;
}
}
int main()
{
// std::cout << "HI World" << std::endl;
matrix_print(matrix_init(2, 3), 2, 3);
return 0;
}
追问
你的这个矩阵不能用
Matrix m = {{1,2,3},{4,5,6}};
构造并初始化...
追答
I am sorry to not read your question carefully.
I guess there would be a solution when you use c++11 to initilize the class constructor, whereas I am unfamiliar with c++ version greater than 98 unfortunately.
Good luck for your happy hunting...
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询