c++ - Error deriving from Boost Rational -
i'm having trouble getting compiler (g++) include header files boost c++ libraries, in subdirectory of bin directory. specifically, i'm trying include rational class header file, rational.hpp. first tried including via scripting code in makefile:
intrational.o: intrational.h g++ -i /home/.../boost_1_58_0 -c intrational.h
however, gives me error:
in file included testrational.cpp:11:0: intrational.h:17:1: error: expected class-name before ‘{’ token { ^ make: *** [testrational.o] error 1
this intrational.h:
#ifndef _intrational_h #define _intrational_h #include<boost/rational.hpp> //derived class class intrational: public rational { bool simplify; public: void setsimple() { simplify=true; }; void setnosimplify() { simplify=false; }; bool getflag() { return simplify; }; }; #endif // _intrational_h
next replaced
#include<boost/rational.hpp>
with full directory
#include</home/.../boost_1_58_0/boost/rational.hpp>
(... represents part of directory shows identity)
this fixed first problem, have new error:
in file included intrational.h:14:0, testrational.cpp:11: /home/.../boost_1_58_0/boost/rational.hpp:82:78: fatal error: boost/integer/common_factor_rt.hpp: no such file or directory #include <boost/integer/common_factor_rt.hpp> // boost::integer::gcd, lcm
this error originates boost library file, rational.hpp. don't want put full directory in #include, because have #include in header files referenced common_factor_rt.hpp instance, , each header file on down, lot of work. shouldn't have to, because kind of defeats purpose of using libraries.
looks want integer rational:
- specify template parameter
rational<>
- qualify base class namespace (it's in
boost
) - ot: don't compile header files: why have header files , .cpp files in c++?
#include <boost/rational.hpp> // derived class class intrational : public boost::rational<int> { bool simplify; public: void setsimple() { simplify = true; } ; void setnosimplify() { simplify = false; } ; bool getflag() { return simplify; } ; };
Comments
Post a Comment