Home > Back-end >  "Undeclared identifier" when trying to define function template
"Undeclared identifier" when trying to define function template

Time:12-25

I want to define a function that decides whether two arrays of doubles are (approximately) equal. Here's my code:

Comparisons.h :

#pragma once
#include <array>

const double EPSILON = 0.0001;

bool areFuzzyEqual(const double& d1, const double& d2);

template<int n>
bool fuzzyEquality((const std::array<double, n>)& a1, (const std::array<double, n>)& a2) {
    bool retVal = True;
    for (int i = 0; i < n; i  ) {
        retVal &= areFuzzyEqual(a1[i], a2[i]);
    }
    return retVal;
};

When I try to compile this project I get errors like

Error C2065 'a1': undeclared identifier

Error C3861 'a1': identifier not found

I don't understand where this error comes from. They're parameters, why would I need to define them?

CodePudding user response:

Just rewrite this line

bool fuzzyEquality((const std::array<double, n>)& a1, (const std::array<double, n>)&a2)

as

bool fuzzyEquality(const std::array<double, n>& a1, const std::array<double, n>& a2)

and you should be good.

  • Related