Hi, I would like to know if something of this sort is legal, standard c++:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
template<typename value>
void Database<value>::select(DBSelectOperation selOp, const string&\
attr,DBQueryOperator op, const value& val){
static string attr_stc;
static DBQueryOperator op_stc;
static value val_stc;
attr_stc = attr;
op_stc = op;
val_stc = val;
struct match_ptr{
typedef Record<value>* argument_type;
typedefbool return_type;
return_type operator()(argument_type a) const{
return a->matchesQuery(attr_stc,op_stc,val_stc);
}
};
......(rest of the function. match_ptr is only used in std::remove_if as the unary operator)
Visual Studio 2012 seems to work fine with it, while gcc complains that the static variables are unused; furthermore, when I set their attributes to "unused", just to disable the warnings (treated as error compulsorily), it seems the line that uses the variables,
return a->matchesQuery(attr_stc,op_stc,val_stc);
produces an "undefined reference" error. So which one of the compilers is behaving according to c++ standard in this case? What is the cause of the undefined reference error and the variables being seen as "unused"?
where interactive.cpp is where the main() function is, and fraction.o is a pre-compiled object file. The "unused variable" warning is given by the first command, while the "undefined reference" error is given by the second.
I first tried compiling all the source files with MSVC, without using any of the given object files compiled with GCC (I was given the source files of fraction.o as well), and the code compiled and ran without any issues; then I tried compiling on linux using GCC, and had the above issues.
If you have the source of fraction.o can you try compiling with that instead of the object file?
The issue is that object files are only good for the same system and same compiler with the same settings that they were compiled with - if anything is off then you get weird errors.
Agh..
I tried compiling the files together, and it does exactly the same thing X-(
the compiling command is:
g++ -std=c++11 -O2 -o db interactive.cpp fraction.cpp
And the compiler output is extremely long and nonsensical. Behold, here's an excerpt: