c++ - Bizarre Undeclared Variable Compiler Error -
problem: compiler declares seemingly nonsensical error local variable in class member function "was not declared in scope". code shown below simplified implementation of original function, , somehow still triggers same error. furthermore, error disappears whenever rename variable (in each place it's used) , resumes change variable original name ("minor"). don't understand behavior , can't find information/posts on cause compiler this. kindly offer suggestions on might wrong? indicative of major bug somewhere else in code (e.g. matrix class definition)?
details: i'm compiling on linux mint 18 using g++ on makefiles generated cmake. i've tried , without variety of compiler options (e.g. -o2, -wall, etc.), , result unchanged. i've compiled , ran earlier version of code/project on windows 7 using mingw , self-written makefile no problems. i'm happy provide additional details upon request.
modified/minimalist code snippet matrix.cpp:
matrix matrix::buildcofactormatrix() const { double minor (0.0); minor = 1.0; return matrix(height_, width_); }
warning message:
/path-to-project-root/src/matrix.cpp: in member function ‘matrix matrix::buildcofactormatrix() const’: /path-to-project-root/src/matrix.cpp:1123:5: error: ‘minor’ not declared in scope minor = 1.0;
2017-08-21 edit: removed unnecessary code , created "minimal, complete, , verifiable" example of problem. me, error seems function of iostream library. if remove iostream inclusion, problem seems disappear. however, error depends on c++ standard used compiling. when specify g++ use, example, -std=c++11 or -std=c++14, problem persists, once remove specification (i.e. g++ -c matrix.cpp), error disappears. way, i'm using g++ 4:5.3.1-1ubu.
unless i'm missing something, can't find macros in iostream, istream, ostream, or ios mention term "minor", perhaps it's further inclusion chain...?
matrix.hpp:
#ifndef matrix_hpp #define matrix_hpp class matrix { public: void buildcofactormatrix() const; }; #endif
matrix.cpp:
#include "matrix.hpp" #include <iostream> void matrix::buildcofactormatrix() const { double minor (0.0); minor = 0.0; }
i can replicate problem adding #define minor(x) (x)
before function.
the macro matches minor(0.0)
not minor
without "parameter".
the line
double minor (0.0);
would replaced by
double (0.0);
which valid, useless, type cast.
so, go evil macro in 1 of include files.
Comments
Post a Comment