刚刚入门c++小白一个,遇到一个小问题,希望大家能够帮我一下 代码如下:
statement.h
#pragma once
#include <vector>
#include <iostream>
typedef std::vector<double> row;
typedef std::vector<std::vector<double>> Matrix;
//LU分解的结构体
//打印矩阵
void printMat(const Matrix& rhs) {
int m = rhs.size();
for (int i = 0; i < m; ++i) {
for (int j = 0; j < m; ++j) {
std::cout << rhs[i][j] << " ";
}
std::cout << std::endl;
}
}
main.cpp
#include <iostream>
#include <cmath>
#include <vector>
#include "statement.h"
typedef double ELEM;
using namespace std;
int main() {
Matrix A = {
{-3,2,6},
{10,-7,0},
{5,-1,5}
};
printMat(A);
}
这样编译没有通过,错误原因提示有重复定义的符号,然后仅仅把printMat()函数放在一个单独的cpp文件就编译通过了,这是为什么呢?