初学C++,一个问题卡了很久了不知道怎么解决。
对这段代码本身的含义不是很清楚,请问这段代码怎么理解,错误应该怎么解决?
https://blog.csdn.net/neo_ustc/article/details/8847911
C++好好的泛型不用,写什么宏。因吹斯听
template <typename T>
void BiLinear(T* buf11, T* buf21, T* buf22, T* buf12, double Dx, double Dy, T* out)
{
auto result = (1 - Dx) * (1 - Dy) *(*buf11)
+ Dx * (1 - Dy) * (*buf21)
+ Dx * Dy * (*buf22)
+ (1 - Dx) * Dy * (*buf12);
*out = (T)result;
}
int main()
{
double Dx = 0.2, Dy = 0.3;
uint16_t matrix1[2][2] = {
{11, 12,},
{21, 22} };
uint16_t result1;
BiLinear(&matrix1[0][0], &matrix1[1][0], &matrix1[1][1], &matrix1[0][1], Dx, Dy, &result1);
uint32_t matrix2[4] = {11, 12, 21, 22};
uint32_t result2;
BiLinear(&matrix2[0], &matrix2[2], &matrix2[3], &matrix2[1], Dx, Dy, &result2);
}