Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"Undeclared identifier" when trying to define function template

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading