This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/SoftwareDesign/Lab1/1-3b/main.cpp

15 lines
538 B
C++
Raw Permalink Normal View History

2022-03-29 05:29:00 +00:00
#include <iostream>
#include "../inc/matrix.hpp"
void print_element(const MatBase<double> &m, int x, int y)
{ // 注意参数是基类
std::cout << m.at(x, y) << std::endl; // 调用虚函数所定义的接口
}
int main()
{
Matrix<double> a(2, 2, 9.0);
Matrix<double> b(2, 2, 7.0);
print_element(a, 0, 0); // 输出 Mat2x2 变量 a 的第一个元素,注意输入是派生类
print_element(b, 0, 0); // 输出 Matrix 变量 b 的第一个元素,注意输入是派生类
}