Related
In my project I have the following piece of code, which works perfectly fine:
#include <optional>
#include <ostream>
using optional_stream_ref = std::optional<std::reference_wrapper<std::ostream>>;
which is then used in functions such as this:
template<typename State, typename Matrix>
inline auto state_energy(const State& state, Matrix& matrix, optional_stream_ref out = std::nullopt) -> typename State::energy_t
{
typename State::energy_t energy = state.calc_energy(matrix, out);
return energy;
}
This compiles and works.
But for some reason when I try to do it in vacuum, just testing, it doesn't compile.
This is main.cpp example:
#include<optional>
#include<ostream>
using optional_stream_ref = std::optional<std::reference_wrapper<std::ostream>>;
void f(int a, optional_stream_ref out = std::nullopt)
{
}
int main()
{
}
which gives this compilation error:
g++ -std=c++17 -O3 -pedantic -Wall -Wextra -Ilib/ -DNDEBUG main.cpp
In file included from /usr/include/c++/9/bits/move.h:55,
from /usr/include/c++/9/bits/nested_exception.h:40,
from /usr/include/c++/9/exception:144,
from /usr/include/c++/9/ios:39,
from /usr/include/c++/9/ostream:38,
from main.cpp:1:
/usr/include/c++/9/type_traits: In instantiation of ‘struct std::__is_trivially_copy_constructible_impl<std::reference_wrapper<std::basic_ostream<char> >, true>’:
/usr/include/c++/9/type_traits:1164:12: required from ‘struct std::is_trivially_copy_constructible<std::reference_wrapper<std::basic_ostream<char> > >’
/usr/include/c++/9/type_traits:2945:25: required from ‘constexpr const bool std::is_trivially_copy_constructible_v<std::reference_wrapper<std::basic_ostream<char> > >’
/usr/include/c++/9/optional:656:11: required from ‘class std::optional<std::reference_wrapper<std::basic_ostream<char> > >’
main.cpp:7:60: required from here
/usr/include/c++/9/type_traits:1157:12: error: invalid use of incomplete type ‘class std::reference_wrapper<std::basic_ostream<char> >’
1157 | struct __is_trivially_copy_constructible_impl<_Tp, true>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/type_traits:2020:11: note: declaration of ‘class std::reference_wrapper<std::basic_ostream<char> >’
2020 | class reference_wrapper;
| ^~~~~~~~~~~~~~~~~
/usr/include/c++/9/type_traits: In instantiation of ‘constexpr const bool std::is_trivially_copy_constructible_v<std::reference_wrapper<std::basic_ostream<char> > >’:
/usr/include/c++/9/optional:656:11: required from ‘class std::optional<std::reference_wrapper<std::basic_ostream<char> > >’
main.cpp:7:60: required from here
/usr/include/c++/9/type_traits:2945:25: error: ‘value’ is not a member of ‘std::is_trivially_copy_constructible<std::reference_wrapper<std::basic_ostream<char> > >’
2945 | inline constexpr bool is_trivially_copy_constructible_v =
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/type_traits: In instantiation of ‘struct std::__is_trivially_move_constructible_impl<std::reference_wrapper<std::basic_ostream<char> >, true>’:
/usr/include/c++/9/type_traits:1185:12: required from ‘struct std::is_trivially_move_constructible<std::reference_wrapper<std::basic_ostream<char> > >’
/usr/include/c++/9/type_traits:2948:25: required from ‘constexpr const bool std::is_trivially_move_constructible_v<std::reference_wrapper<std::basic_ostream<char> > >’
/usr/include/c++/9/optional:656:11: required from ‘class std::optional<std::reference_wrapper<std::basic_ostream<char> > >’
main.cpp:7:60: required from here
/usr/include/c++/9/type_traits:1178:12: error: invalid use of incomplete type ‘class std::reference_wrapper<std::basic_ostream<char> >’
1178 | struct __is_trivially_move_constructible_impl<_Tp, true>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/type_traits:2020:11: note: declaration of ‘class std::reference_wrapper<std::basic_ostream<char> >’
2020 | class reference_wrapper;
| ^~~~~~~~~~~~~~~~~
/usr/include/c++/9/type_traits: In instantiation of ‘constexpr const bool std::is_trivially_move_constructible_v<std::reference_wrapper<std::basic_ostream<char> > >’:
/usr/include/c++/9/optional:656:11: required from ‘class std::optional<std::reference_wrapper<std::basic_ostream<char> > >’
main.cpp:7:60: required from here
/usr/include/c++/9/type_traits:2948:25: error: ‘value’ is not a member of ‘std::is_trivially_move_constructible<std::reference_wrapper<std::basic_ostream<char> > >’
2948 | inline constexpr bool is_trivially_move_constructible_v =
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Why can it compile in one place, but fail in another?
Where is the error?
Thanks!
#include <functional> to get the canonical definition of std::reference_wrapper.
As a general rule, cppreference includes the #include required for each std library template and type. So I just google it ("reference wrapper cppreference", misspellings ok) and look at the top of the page.
C++ std header files are free to include other std header files, types and template, or forward declare them. But if you want to reliably and portably use a template or type from std, you need to #include the correct header.
To diagnose this problem yourself from an error-stream, first look for the first error in it:
/usr/include/c++/9/type_traits:1157:12: error: invalid use of incomplete type ‘class std::reference_wrapper<std::basic_ostream<char> >’
It states std::reference_wrapper is incomplete. Then you can try to work out why this error is generated either from that one line, or you can follow the "breadcrumbs" of how you got there. Here, simply looking at that error line makes the solution relatively obvious; find a way to make std::reference_wrapper complete.
(I had seen this problem before, so I just assumed the std construct you didn't obviously #include a header for was missing, without having to look at your error messages.)
I've got the following code:
#include <iostream>
#include <eigen3/Eigen/Dense>
class MyVectorType: public Eigen::Matrix<double, 3, 1> {
public:
MyVectorType(void) :
Eigen::Matrix<double, 3, 1>() {
}
typedef Eigen::Matrix<double, 3, 1> Base;
// This constructor allows you to construct MyVectorType from Eigen expressions
template<typename OtherDerived>
MyVectorType(const Eigen::MatrixBase<OtherDerived>& other) :
Eigen::Matrix<double, 3, 1>(other) {
}
// This method allows you to assign Eigen expressions to MyVectorType
template<typename OtherDerived>
MyVectorType & operator=(const Eigen::MatrixBase<OtherDerived>& other) {
this->Base::operator=(other);
return *this;
}
//other custom methods here
};
void init(Eigen::Ref<MyVectorType>& m) {
for (int i = 0; i < 3; i++)
for (int j = 0; j < 1; j++)
m(i, j) = 1;
}
int main() {
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::AutoAlign, 12,
12> mm(3, 1);
Eigen::Ref<MyVectorType> rr(mm);
init(rr);
std::cout << mm << std::endl;
return 0;
}
I defined my own class but when I try to the Ref class I have the following error from gcc:
make all
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -std=c++98 -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.o" -o "main.o" "../main.cpp"
In file included from /usr/include/eigen3/Eigen/Core:449:0,
from /usr/include/eigen3/Eigen/Dense:1,
from ../main.cpp:2:
/usr/include/eigen3/Eigen/src/Core/Map.h: In instantiation of ‘struct Eigen::internal::traits<Eigen::Map<MyVectorType, 0, Eigen::OuterStride<> > >’:
/usr/include/eigen3/Eigen/src/Core/Ref.h:18:8: required from ‘struct Eigen::internal::traits<Eigen::Ref<MyVectorType> >’
/usr/include/eigen3/Eigen/src/Core/util/ForwardDeclarations.h:32:54: required from ‘struct Eigen::internal::accessors_level<Eigen::Ref<MyVectorType> >’
/usr/include/eigen3/Eigen/src/Core/util/ForwardDeclarations.h:113:75: required from ‘class Eigen::RefBase<Eigen::Ref<MyVectorType> >’
/usr/include/eigen3/Eigen/src/Core/Ref.h:190:76: required from ‘class Eigen::Ref<MyVectorType>’
../main.cpp:26:10: required from here
/usr/include/eigen3/Eigen/src/Core/Map.h:18:8: error: invalid use of incomplete type ‘struct Eigen::internal::traits<MyVectorType>’
struct traits<Map<PlainObjectType, MapOptions, StrideType> >
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/eigen3/Eigen/Core:346:0,
from /usr/include/eigen3/Eigen/Dense:1,
from ../main.cpp:2:
/usr/include/eigen3/Eigen/src/Core/util/ForwardDeclarations.h:17:29: note: declaration of ‘struct Eigen::internal::traits<MyVectorType>’
template<typename T> struct traits;
^~~~~~
In file included from /usr/include/eigen3/Eigen/Core:449:0,
from /usr/include/eigen3/Eigen/Dense:1,
from ../main.cpp:2:
/usr/include/eigen3/Eigen/src/Core/Map.h:30:32: error: incomplete type ‘Eigen::internal::traits<Eigen::Map<MyVectorType, 0, Eigen::OuterStride<> > >::TraitsBase {aka Eigen::internal::traits<MyVectorType>}’ used in nested name specifier
Flags0 = TraitsBase::Flags & (~NestByRefBit),
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/eigen3/Eigen/Core:348:0,
from /usr/include/eigen3/Eigen/Dense:1,
from ../main.cpp:2:
/usr/include/eigen3/Eigen/src/Core/util/XprHelper.h: In instantiation of ‘struct Eigen::internal::is_lvalue<MyVectorType>’:
/usr/include/eigen3/Eigen/src/Core/Map.h:31:47: required from ‘struct Eigen::internal::traits<Eigen::Map<MyVectorType, 0, Eigen::OuterStride<> > >’
/usr/include/eigen3/Eigen/src/Core/Ref.h:18:8: required from ‘struct Eigen::internal::traits<Eigen::Ref<MyVectorType> >’
/usr/include/eigen3/Eigen/src/Core/util/ForwardDeclarations.h:32:54: required from ‘struct Eigen::internal::accessors_level<Eigen::Ref<MyVectorType> >’
/usr/include/eigen3/Eigen/src/Core/util/ForwardDeclarations.h:113:75: required from ‘class Eigen::RefBase<Eigen::Ref<MyVectorType> >’
/usr/include/eigen3/Eigen/src/Core/Ref.h:190:76: required from ‘class Eigen::Ref<MyVectorType>’
../main.cpp:26:10: required from here
/usr/include/eigen3/Eigen/src/Core/util/XprHelper.h:642:53: error: incomplete type ‘Eigen::internal::traits<MyVectorType>’ used in nested name specifier
bool(traits<ExpressionType>::Flags & LvalueBit) };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
In file included from /usr/include/eigen3/Eigen/Core:448:0,
from /usr/include/eigen3/Eigen/Dense:1,
from ../main.cpp:2:
/usr/include/eigen3/Eigen/src/Core/MapBase.h: In instantiation of ‘class Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>’:
/usr/include/eigen3/Eigen/src/Core/Ref.h:58:34: required from ‘class Eigen::RefBase<Eigen::Ref<MyVectorType> >’
/usr/include/eigen3/Eigen/src/Core/Ref.h:190:76: required from ‘class Eigen::Ref<MyVectorType>’
../main.cpp:26:10: required from here
/usr/include/eigen3/Eigen/src/Core/MapBase.h:37:34: error: no type named ‘XprKind’ in ‘struct Eigen::internal::traits<Eigen::Ref<MyVectorType> >’
template<typename Derived> class MapBase<Derived, ReadOnlyAccessors>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:42:62: error: no type named ‘XprKind’ in ‘struct Eigen::internal::traits<Eigen::Ref<MyVectorType> >’
typedef typename internal::dense_xpr_base<Derived>::type Base;
^~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:43:10: error: ‘RowsAtCompileTime’ is not a member of ‘Eigen::internal::traits<Eigen::Ref<MyVectorType> >’
enum {
^
/usr/include/eigen3/Eigen/src/Core/MapBase.h:43:10: error: ‘ColsAtCompileTime’ is not a member of ‘Eigen::internal::traits<Eigen::Ref<MyVectorType> >’
/usr/include/eigen3/Eigen/src/Core/MapBase.h:49:61: error: no type named ‘StorageKind’ in ‘struct Eigen::internal::traits<Eigen::Ref<MyVectorType> >’
typedef typename internal::traits<Derived>::StorageKind StorageKind;
^~~~~~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:50:56: error: no type named ‘Scalar’ in ‘struct Eigen::internal::traits<Eigen::Ref<MyVectorType> >’
typedef typename internal::traits<Derived>::Scalar Scalar;
^~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:51:60: error: no type named ‘Scalar’ in ‘struct Eigen::internal::traits<Eigen::Ref<MyVectorType> >’
typedef typename internal::packet_traits<Scalar>::type PacketScalar;
^~~~~~~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:52:46: error: no type named ‘Scalar’ in ‘struct Eigen::internal::traits<Eigen::Ref<MyVectorType> >’
typedef typename NumTraits<Scalar>::Real RealScalar;
^~~~~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:57:22: error: no type named ‘Scalar’ in ‘struct Eigen::internal::traits<Eigen::Ref<MyVectorType> >’
PointerType;
^~~~~~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:59:17: error: using-declaration for non-member at class scope
using Base::derived;
^~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:63:17: error: using-declaration for non-member at class scope
using Base::MaxRowsAtCompileTime;
^~~~~~~~~~~~~~~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:64:17: error: using-declaration for non-member at class scope
using Base::MaxColsAtCompileTime;
^~~~~~~~~~~~~~~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:65:17: error: using-declaration for non-member at class scope
using Base::MaxSizeAtCompileTime;
^~~~~~~~~~~~~~~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:66:17: error: using-declaration for non-member at class scope
using Base::IsVectorAtCompileTime;
^~~~~~~~~~~~~~~~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:67:17: error: using-declaration for non-member at class scope
using Base::Flags;
^~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:68:17: error: using-declaration for non-member at class scope
using Base::IsRowMajor;
^~~~~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:70:17: error: using-declaration for non-member at class scope
using Base::rows;
^~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:71:17: error: using-declaration for non-member at class scope
using Base::cols;
^~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:72:17: error: using-declaration for non-member at class scope
using Base::size;
^~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:73:17: error: using-declaration for non-member at class scope
using Base::coeff;
^~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:74:17: error: using-declaration for non-member at class scope
using Base::coeffRef;
^~~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:75:17: error: using-declaration for non-member at class scope
using Base::lazyAssign;
^~~~~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:76:17: error: using-declaration for non-member at class scope
using Base::eval;
^~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:78:17: error: using-declaration for non-member at class scope
using Base::innerStride;
^~~~~~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:79:17: error: using-declaration for non-member at class scope
using Base::outerStride;
^~~~~~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:80:17: error: using-declaration for non-member at class scope
using Base::rowStride;
^~~~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:81:17: error: using-declaration for non-member at class scope
using Base::colStride;
^~~~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:84:25: error: using-declaration for non-member at class scope
using Base::operator=;
^
In file included from /usr/include/eigen3/Eigen/Core:72:0,
from /usr/include/eigen3/Eigen/Dense:1,
from ../main.cpp:2:
/usr/include/eigen3/Eigen/src/Core/Ref.h: In instantiation of ‘class Eigen::RefBase<Eigen::Ref<MyVectorType> >’:
/usr/include/eigen3/Eigen/src/Core/Ref.h:190:76: required from ‘class Eigen::Ref<MyVectorType>’
../main.cpp:26:10: required from here
/usr/include/eigen3/Eigen/src/Core/Ref.h:67:3: error: no type named ‘Scalar’ in ‘struct Eigen::internal::traits<Eigen::RefBase<Eigen::Ref<MyVectorType> > >’
EIGEN_DENSE_PUBLIC_INTERFACE(RefBase)
^
/usr/include/eigen3/Eigen/src/Core/Ref.h:67:3: error: no type named ‘Scalar’ in ‘struct Eigen::internal::traits<Eigen::RefBase<Eigen::Ref<MyVectorType> > >’
EIGEN_DENSE_PUBLIC_INTERFACE(RefBase)
^
In file included from /usr/include/eigen3/Eigen/Core:72:0,
from /usr/include/eigen3/Eigen/Dense:1,
from ../main.cpp:2:
/usr/include/eigen3/Eigen/src/Core/Ref.h:67:3: error: no type named ‘StorageKind’ in ‘struct Eigen::internal::traits<Eigen::RefBase<Eigen::Ref<MyVectorType> > >’
EIGEN_DENSE_PUBLIC_INTERFACE(RefBase)
^
/usr/include/eigen3/Eigen/src/Core/Ref.h:67:3: error: no type named ‘StorageIndex’ in ‘struct Eigen::internal::traits<Eigen::RefBase<Eigen::Ref<MyVectorType> > >’
EIGEN_DENSE_PUBLIC_INTERFACE(RefBase)
^
/usr/include/eigen3/Eigen/src/Core/Ref.h:67:3: error: ‘RowsAtCompileTime’ is not a member of ‘Eigen::internal::traits<Eigen::RefBase<Eigen::Ref<MyVectorType> > >’
EIGEN_DENSE_PUBLIC_INTERFACE(RefBase)
^
/usr/include/eigen3/Eigen/src/Core/Ref.h:67:3: error: ‘ColsAtCompileTime’ is not a member of ‘Eigen::internal::traits<Eigen::RefBase<Eigen::Ref<MyVectorType> > >’
/usr/include/eigen3/Eigen/src/Core/Ref.h:67:3: error: ‘MaxSizeAtCompileTime’ is not a member of ‘Eigen::RefBase<Eigen::Ref<MyVectorType> >::Base {aka Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>}’
/usr/include/eigen3/Eigen/src/Core/Ref.h:67:3: error: ‘IsVectorAtCompileTime’ is not a member of ‘Eigen::RefBase<Eigen::Ref<MyVectorType> >::Base {aka Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>}’
/usr/include/eigen3/Eigen/src/Core/Ref.h:67:3: error: no members matching ‘Eigen::RefBase<Eigen::Ref<MyVectorType> >::Base {aka Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>}::derived’ in ‘Eigen::RefBase<Eigen::Ref<MyVectorType> >::Base {aka class Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>}’
EIGEN_DENSE_PUBLIC_INTERFACE(RefBase)
^
/usr/include/eigen3/Eigen/src/Core/Ref.h:67:3: error: no members matching ‘Eigen::RefBase<Eigen::Ref<MyVectorType> >::Base {aka Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>}::const_cast_derived’ in ‘Eigen::RefBase<Eigen::Ref<MyVectorType> >::Base {aka class Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>}’
EIGEN_DENSE_PUBLIC_INTERFACE(RefBase)
^
In file included from /usr/include/eigen3/Eigen/Core:72:0,
from /usr/include/eigen3/Eigen/Dense:1,
from ../main.cpp:2:
/usr/include/eigen3/Eigen/src/Core/Ref.h: In instantiation of ‘class Eigen::Ref<MyVectorType>’:
../main.cpp:26:10: required from here
/usr/include/eigen3/Eigen/src/Core/Ref.h:201:5: error: no type named ‘Scalar’ in ‘struct Eigen::internal::traits<Eigen::Ref<MyVectorType> >’
EIGEN_DENSE_PUBLIC_INTERFACE(Ref)
^
/usr/include/eigen3/Eigen/src/Core/Ref.h:201:5: error: no type named ‘Scalar’ in ‘struct Eigen::internal::traits<Eigen::Ref<MyVectorType> >’
EIGEN_DENSE_PUBLIC_INTERFACE(Ref)
^
In file included from /usr/include/eigen3/Eigen/Core:72:0,
from /usr/include/eigen3/Eigen/Dense:1,
from ../main.cpp:2:
/usr/include/eigen3/Eigen/src/Core/Ref.h:201:5: error: no type named ‘StorageKind’ in ‘struct Eigen::internal::traits<Eigen::Ref<MyVectorType> >’
EIGEN_DENSE_PUBLIC_INTERFACE(Ref)
^
/usr/include/eigen3/Eigen/src/Core/Ref.h:201:5: error: no type named ‘StorageIndex’ in ‘struct Eigen::internal::traits<Eigen::Ref<MyVectorType> >’
EIGEN_DENSE_PUBLIC_INTERFACE(Ref)
^
/usr/include/eigen3/Eigen/src/Core/Ref.h:201:5: error: ‘RowsAtCompileTime’ is not a member of ‘Eigen::internal::traits<Eigen::Ref<MyVectorType> >’
EIGEN_DENSE_PUBLIC_INTERFACE(Ref)
^
/usr/include/eigen3/Eigen/src/Core/Ref.h:201:5: error: ‘ColsAtCompileTime’ is not a member of ‘Eigen::internal::traits<Eigen::Ref<MyVectorType> >’
/usr/include/eigen3/Eigen/src/Core/Ref.h:201:5: error: no members matching ‘Eigen::Ref<MyVectorType>::Base {aka Eigen::RefBase<Eigen::Ref<MyVectorType> >}::derived’ in ‘Eigen::Ref<MyVectorType>::Base {aka class Eigen::RefBase<Eigen::Ref<MyVectorType> >}’
EIGEN_DENSE_PUBLIC_INTERFACE(Ref)
^
/usr/include/eigen3/Eigen/src/Core/Ref.h:201:5: error: no members matching ‘Eigen::Ref<MyVectorType>::Base {aka Eigen::RefBase<Eigen::Ref<MyVectorType> >}::const_cast_derived’ in ‘Eigen::Ref<MyVectorType>::Base {aka class Eigen::RefBase<Eigen::Ref<MyVectorType> >}’
EIGEN_DENSE_PUBLIC_INTERFACE(Ref)
^
../main.cpp: In function ‘void init(Eigen::Ref<MyVectorType>&)’:
../main.cpp:26:10: error: no match for call to ‘(Eigen::Ref<MyVectorType>) (int&, int&)’
m(i, j) = 1;
^
In file included from /usr/include/eigen3/Eigen/Core:450:0,
from /usr/include/eigen3/Eigen/Dense:1,
from ../main.cpp:2:
/usr/include/eigen3/Eigen/src/Core/Ref.h: In instantiation of ‘struct Eigen::internal::traits<Eigen::Ref<MyVectorType> >::match<Eigen::Matrix<double, -1, -1, 0, 12, 12> >’:
/usr/include/eigen3/Eigen/src/Core/Ref.h:197:63: required by substitution of ‘template<class Derived> Eigen::Ref<MyVectorType>::Ref(const Eigen::PlainObjectBase<Derived>&, typename Eigen::internal::enable_if<(bool)(Eigen::internal::traits<Eigen::Ref<MyVectorType> >::match<Derived>::MatchAtCompileTime), Derived>::type*) [with Derived = Eigen::Matrix<double, -1, -1, 0, 12, 12>]’
../main.cpp:32:32: required from here
/usr/include/eigen3/Eigen/src/Core/Ref.h:44:25: error: incomplete type ‘Eigen::internal::traits<MyVectorType>’ used in nested name specifier
AlignmentMatch = (int(traits<PlainObjectType>::Alignment)==int(Unaligned)) || (DerivedAlignment >= int(Alignment)), // FIXME the first condition is not very clear, it should be replaced by the required alignment
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/eigen3/Eigen/Core:347:0,
from /usr/include/eigen3/Eigen/Dense:1,
from ../main.cpp:2:
/usr/include/eigen3/Eigen/src/Core/PlainObjectBase.h: In instantiation of ‘static void Eigen::PlainObjectBase<Derived>::_check_template_params() [with Derived = Eigen::Matrix<double, 3, 1, 0, 12, 12>]’:
/usr/include/eigen3/Eigen/src/Core/Matrix.h:261:35: required from ‘Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::Matrix() [with _Scalar = double; int _Rows = 3; int _Cols = 1; int _Options = 0; int _MaxRows = 12; int _MaxCols = 12]’
../main.cpp:7:58: required from here
/usr/include/eigen3/Eigen/src/Core/PlainObjectBase.h:899:7: error: ‘INVALID_MATRIX_TEMPLATE_PARAMETERS’ is not a member of ‘Eigen::internal::static_assertion<false>’
EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, (Options&RowMajor)==RowMajor)
^
In file included from /usr/include/eigen3/Eigen/Core:450:0,
from /usr/include/eigen3/Eigen/Dense:1,
from ../main.cpp:2:
/usr/include/eigen3/Eigen/src/Core/Ref.h: In instantiation of ‘Eigen::RefBase<Derived>::RefBase() [with Derived = Eigen::Ref<MyVectorType>]’:
/usr/include/eigen3/Eigen/src/Core/Ref.h:208:5: required from ‘Eigen::Ref<PlainObjectType, Options, StrideType>::Ref(Eigen::PlainObjectBase<OtherDerived>&, typename Eigen::internal::enable_if<(bool)(typename Eigen::internal::traits<Eigen::Ref<PlainObjectType, RefOptions, StrideType> >::match<Derived>::MatchAtCompileTime), Derived>::type*) [with Derived = Eigen::Matrix<double, -1, -1, 0, 12, 12>; PlainObjectType = MyVectorType; int Options = 0; StrideType = Eigen::OuterStride<>; typename Eigen::internal::enable_if<(bool)(typename Eigen::internal::traits<Eigen::Ref<PlainObjectType, RefOptions, StrideType> >::match<Derived>::MatchAtCompileTime), Derived>::type = Eigen::Matrix<double, -1, -1, 0, 12, 12>]’
../main.cpp:32:32: required from here
/usr/include/eigen3/Eigen/src/Core/Ref.h:86:100: error: no matching function for call to ‘Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>::MapBase(int, int, int)’
StrideType::InnerStrideAtCompileTime==Dynamic?0:StrideType::InnerStrideAtCompileTime)
^
In file included from /usr/include/eigen3/Eigen/Core:448:0,
from /usr/include/eigen3/Eigen/Dense:1,
from ../main.cpp:2:
/usr/include/eigen3/Eigen/src/Core/MapBase.h:37:34: note: candidate: Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>::MapBase()
template<typename Derived> class MapBase<Derived, ReadOnlyAccessors>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:37:34: note: candidate expects 0 arguments, 3 provided
/usr/include/eigen3/Eigen/src/Core/MapBase.h:37:34: note: candidate: Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>::MapBase(const Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>&)
/usr/include/eigen3/Eigen/src/Core/MapBase.h:37:34: note: candidate expects 1 argument, 3 provided
In file included from /usr/include/eigen3/Eigen/Core:450:0,
from /usr/include/eigen3/Eigen/Dense:1,
from ../main.cpp:2:
/usr/include/eigen3/Eigen/src/Core/Ref.h: In instantiation of ‘void Eigen::RefBase<Derived>::construct(Expression&) [with Expression = Eigen::Matrix<double, -1, -1, 0, 12, 12>; Derived = Eigen::Ref<MyVectorType>]’:
/usr/include/eigen3/Eigen/src/Core/Ref.h:210:22: required from ‘Eigen::Ref<PlainObjectType, Options, StrideType>::Ref(Eigen::PlainObjectBase<OtherDerived>&, typename Eigen::internal::enable_if<(bool)(typename Eigen::internal::traits<Eigen::Ref<PlainObjectType, RefOptions, StrideType> >::match<Derived>::MatchAtCompileTime), Derived>::type*) [with Derived = Eigen::Matrix<double, -1, -1, 0, 12, 12>; PlainObjectType = MyVectorType; int Options = 0; StrideType = Eigen::OuterStride<>; typename Eigen::internal::enable_if<(bool)(typename Eigen::internal::traits<Eigen::Ref<PlainObjectType, RefOptions, StrideType> >::match<Derived>::MatchAtCompileTime), Derived>::type = Eigen::Matrix<double, -1, -1, 0, 12, 12>]’
../main.cpp:32:32: required from here
/usr/include/eigen3/Eigen/src/Core/Ref.h:101:7: error: no matching function for call to ‘Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>::MapBase(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, 12, 12> >::Scalar*, int, Eigen::EigenBase<Eigen::Matrix<double, -1, -1, 0, 12, 12> >::Index)’
::new (static_cast<Base*>(this)) Base(expr.data(), 1, expr.size());
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/eigen3/Eigen/Core:448:0,
from /usr/include/eigen3/Eigen/Dense:1,
from ../main.cpp:2:
/usr/include/eigen3/Eigen/src/Core/MapBase.h:37:34: note: candidate: Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>::MapBase()
template<typename Derived> class MapBase<Derived, ReadOnlyAccessors>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:37:34: note: candidate expects 0 arguments, 3 provided
/usr/include/eigen3/Eigen/src/Core/MapBase.h:37:34: note: candidate: Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>::MapBase(const Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>&)
/usr/include/eigen3/Eigen/src/Core/MapBase.h:37:34: note: candidate expects 1 argument, 3 provided
In file included from /usr/include/eigen3/Eigen/Core:450:0,
from /usr/include/eigen3/Eigen/Dense:1,
from ../main.cpp:2:
/usr/include/eigen3/Eigen/src/Core/Ref.h:106:7: error: no matching function for call to ‘Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>::MapBase(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, 12, 12> >::Scalar*, Eigen::EigenBase<Eigen::Matrix<double, -1, -1, 0, 12, 12> >::Index, int)’
::new (static_cast<Base*>(this)) Base(expr.data(), expr.size(), 1);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/eigen3/Eigen/Core:448:0,
from /usr/include/eigen3/Eigen/Dense:1,
from ../main.cpp:2:
/usr/include/eigen3/Eigen/src/Core/MapBase.h:37:34: note: candidate: Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>::MapBase()
template<typename Derived> class MapBase<Derived, ReadOnlyAccessors>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:37:34: note: candidate expects 0 arguments, 3 provided
/usr/include/eigen3/Eigen/src/Core/MapBase.h:37:34: note: candidate: Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>::MapBase(const Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>&)
/usr/include/eigen3/Eigen/src/Core/MapBase.h:37:34: note: candidate expects 1 argument, 3 provided
In file included from /usr/include/eigen3/Eigen/Core:450:0,
from /usr/include/eigen3/Eigen/Dense:1,
from ../main.cpp:2:
/usr/include/eigen3/Eigen/src/Core/Ref.h:109:7: error: no matching function for call to ‘Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>::MapBase(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, 12, 12> >::Scalar*, Eigen::Index, Eigen::Index)’
::new (static_cast<Base*>(this)) Base(expr.data(), expr.rows(), expr.cols());
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/eigen3/Eigen/Core:448:0,
from /usr/include/eigen3/Eigen/Dense:1,
from ../main.cpp:2:
/usr/include/eigen3/Eigen/src/Core/MapBase.h:37:34: note: candidate: Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>::MapBase()
template<typename Derived> class MapBase<Derived, ReadOnlyAccessors>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/eigen3/Eigen/src/Core/MapBase.h:37:34: note: candidate expects 0 arguments, 3 provided
/usr/include/eigen3/Eigen/src/Core/MapBase.h:37:34: note: candidate: Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>::MapBase(const Eigen::MapBase<Eigen::Ref<MyVectorType>, 0>&)
/usr/include/eigen3/Eigen/src/Core/MapBase.h:37:34: note: candidate expects 1 argument, 3 provided
Is possible to pass by reference a dynamic matrix to a fixed one using a custom child class?
Eigen::Ref is not intended to work with own custom types (that would be possible, but is way to complicated for this purpose). Simply use Eigen::Ref<MyVectorType::Base>. Also if a Ref is intended to be an L-value (i.e., writable), you should pass it by-value, like so
void init(Eigen::Ref<MyVectorType::Base> m) {
// ...
That way you don't need to manually generate a temporary when calling init:
int main() {
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::AutoAlign, 12,
12> mm(3, 1);
// Eigen::Ref<MyVectorType> rr(mm); // not necessary!
init(mm); // implicitly generates a temporary `Ref` object
// ...
For more details, see the online documentation of Ref: https://eigen.tuxfamily.org/dox/classEigen_1_1Ref.html
Every time I make a new project in Eclipse Oxygen CDT, I'm always plagued by three main errors: "Type 'std::string' could not be resolved" (or similar inclusion problems), "Launch failed. Binaries not found," and "Launch failed. Program file does not exist".
I feel like I have tried just about everything. I have researched and followed these questions: Eclipse C++: Symbol 'std' could not be resolved
, The program file specified in the launch configuration does not exist, Launch Failed Binary not found Eclipse for C in Windows
, Eclipse CDT project built but “Launch Failed. Binary Not Found”
, “string could not resolved” error in Eclipse for C++ (Eclipse can't resolve standard library)
, C++ - Unresolved inclusion: iostream
, Eclipse c++ Type could not be resolved error even though build is successful
, and How to include a file from another folder?
.
Hi World Example:
/*
* Hi_world.cpp
*
* Created on: Feb 22, 2018
* Author: Me
*/
//I tried using the actual file paths but that didn't help either
#include <C:\MinGW\lib\gcc\mingw32\5.3.0\include\c++\iostream>
#include <C:\MinGW\include\string.h>
using namespace std;//"Symbol 'std' could not be resolved"
int main()
{
std::string me = "hi world";//"Type 'std::string' could not be resolved"
std::cout << me << std::endl;//"Symbol 'cout' could not be resolved"
// and "Symbol 'endl' could not be resolved"
}
Note: I tried to get this to run for several hours one day, was unsuccessful, so I saved and exited eclipse and my computer. The next day I turned on my computer, cleaned, built, and ran my this program as is, and it ran corectly on first try (although the red squiggly lines didn't disappear).
Hear is this Programs build log:
12:37:15 **** Rebuild of configuration Debug for project Hi world ****
Info: Internal Builder is used for build
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o Hi_world.o "..\\Hi_world.cpp"
g++ "-LC:\\MinGW" -o "Hi world.exe" Hi_world.o
12:37:17 Build Finished (took 1s.47ms)
Hear is another example that still doesn't Run:
#include <iostream>
#include "stdio.h"
#include "time.h"
#include "string.h"
int main ()
{
time_t timer;
struct tm y2k = {0};
double seconds;
y2k.tm_hour = 0; y2k.tm_min = 0; y2k.tm_sec = 0;
y2k.tm_year = 100; y2k.tm_mon = 0; y2k.tm_mday = 1;
time(&timer); /* get current time; same as: timer = time(NULL) */
seconds = difftime(timer,mktime(&y2k));
printf ("%.f seconds since January 1, 2000 in the current timezone", seconds);
return 0;
}
Note: This had all the inclusion errors mentioned before, but randomly between a clean and rebuild those red squiggly errors went away. However it still doesn't build and run correctly with the error message "Launch failed. Binary not found."
Hear is this programs build log:
12:40:10 **** Rebuild of configuration Debug for project Time ****
Info: Internal Builder is used for build
g++ "-IC:\\MinGW\\lib\\gcc\\mingw32\\5.3.0\\include\\c++\\debug" -O0 -g3 -Wall -c -fmessage-length=0 -o Time.o "..\\Time.cpp"
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\basic_ios.h:37:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:44,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.h: In member function 'std::__cxx11::string std::__cxx11::numpunct<_CharT>::grouping() const':
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.h:1777:7: error: return type 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}' is incomplete
{ return this->do_grouping(); }
^
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.h: In member function 'virtual std::__cxx11::string std::__cxx11::numpunct<_CharT>::do_grouping() const':
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.h:1845:7: error: return type 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}' is incomplete
{ return _M_data->_M_grouping; }
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.h:2651:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\basic_ios.h:37,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:44,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc: In member function 'void std::__numpunct_cache<_CharT>::_M_cache(const std::locale&)':
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc:88:26: error: invalid use of incomplete type 'const string {aka const class std::__cxx11::basic_string<char>}'
_M_grouping_size = __g.size();
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iosfwd:39:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\stringfwd.h:71:11: note: declaration of 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
class basic_string;
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.h:2651:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\basic_ios.h:37,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:44,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc:90:7: error: invalid use of incomplete type 'const string {aka const class std::__cxx11::basic_string<char>}'
__g.copy(__grouping, _M_grouping_size);
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iosfwd:39:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\stringfwd.h:71:11: note: declaration of 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
class basic_string;
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.h:2651:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\basic_ios.h:37,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:44,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc: In member function '_InIter std::num_get<_CharT, _InIter>::_M_extract_float(_InIter, _InIter, std::ios_base&, std::ios_base::iostate&, std::__cxx11::string&) const':
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc:211:18: error: invalid use of incomplete type 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
__found_grouping.reserve(32);
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iosfwd:39:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\stringfwd.h:71:11: note: declaration of 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
class basic_string;
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.h:2651:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\basic_ios.h:37,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:44,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc:282:10: error: invalid use of incomplete type 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
__xtrc.clear();
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iosfwd:39:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\stringfwd.h:71:11: note: declaration of 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
class basic_string;
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.h:2651:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\basic_ios.h:37,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:44,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc:296:27: error: invalid use of incomplete type 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
if (__found_grouping.size())
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iosfwd:39:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\stringfwd.h:71:11: note: declaration of 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
class basic_string;
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.h:2651:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\basic_ios.h:37,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:44,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc:319:27: error: invalid use of incomplete type 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
if (__found_grouping.size() && !__found_dec)
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iosfwd:39:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\stringfwd.h:71:11: note: declaration of 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
class basic_string;
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.h:2651:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\basic_ios.h:37,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:44,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc:355:27: error: invalid use of incomplete type 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
if (__found_grouping.size())
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iosfwd:39:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\stringfwd.h:71:11: note: declaration of 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
class basic_string;
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.h:2651:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\basic_ios.h:37,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:44,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc: In member function '_InIter std::num_get<_CharT, _InIter>::_M_extract_int(_InIter, _InIter, std::ios_base&, std::ios_base::iostate&, _ValueT&) const':
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc:468:20: error: invalid use of incomplete type 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
__found_grouping.reserve(32);
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iosfwd:39:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\stringfwd.h:71:11: note: declaration of 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
class basic_string;
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.h:2651:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\basic_ios.h:37,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:44,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc:554:22: error: invalid use of incomplete type 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
if (__found_grouping.size())
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iosfwd:39:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\stringfwd.h:71:11: note: declaration of 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
class basic_string;
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.h:2651:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\basic_ios.h:37,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:44,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc:567:55: error: invalid use of incomplete type 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
if ((!__sep_pos && !__found_zero && !__found_grouping.size())
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iosfwd:39:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\stringfwd.h:71:11: note: declaration of 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
class basic_string;
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.h:2651:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\basic_ios.h:37,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:44,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc: In member function 'virtual _InIter std::num_get<_CharT, _InIter>::do_get(std::num_get<_CharT, _InIter>::iter_type, std::num_get<_CharT, _InIter>::iter_type, std::ios_base&, std::ios_base::iostate&, float&) const':
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc:695:13: error: invalid use of incomplete type 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
__xtrc.reserve(32);
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iosfwd:39:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\stringfwd.h:71:11: note: declaration of 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
class basic_string;
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.h:2651:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\basic_ios.h:37,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:44,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc:697:33: error: invalid use of incomplete type 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iosfwd:39:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\stringfwd.h:71:11: note: declaration of 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
class basic_string;
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.h:2651:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\basic_ios.h:37,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:44,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc: In member function 'virtual _InIter std::num_get<_CharT, _InIter>::do_get(std::num_get<_CharT, _InIter>::iter_type, std::num_get<_CharT, _InIter>::iter_type, std::ios_base&, std::ios_base::iostate&, double&) const':
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc:710:13: error: invalid use of incomplete type 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
__xtrc.reserve(32);
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iosfwd:39:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\stringfwd.h:71:11: note: declaration of 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
class basic_string;
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.h:2651:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\basic_ios.h:37,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:44,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc:712:33: error: invalid use of incomplete type 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iosfwd:39:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\stringfwd.h:71:11: note: declaration of 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
class basic_string;
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.h:2651:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\basic_ios.h:37,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:44,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc: In member function 'virtual _InIter std::num_get<_CharT, _InIter>::do_get(std::num_get<_CharT, _InIter>::iter_type, std::num_get<_CharT, _InIter>::iter_type, std::ios_base&, std::ios_base::iostate&, long double&) const':
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc:742:13: error: invalid use of incomplete type 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
__xtrc.reserve(32);
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iosfwd:39:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\stringfwd.h:71:11: note: declaration of 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
class basic_string;
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.h:2651:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\basic_ios.h:37,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:44,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_facets.tcc:744:33: error: invalid use of incomplete type 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iosfwd:39:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\Time.cpp:8:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\stringfwd.h:71:11: note: declaration of 'std::__cxx11::string {aka class std::__cxx11::basic_string<char>}'
class basic_string;
^
12:40:10 Build Finished (took 656ms)
I am using a native install of Windows 10, and am using MinGW installed on my computer. What is strange about this problem is that I will start a new project, the inclusion errors will pop up, making it not be able to build or run, and thus causing the other two errors, I will then battle it for days, following the answers above and get no where. Then out of the blue, I will click "build and run" and the program will build correctly and run properly (so long as I don't changing the code or click "Clean" thereafter). It gets even worse if I try to make a class and include the classes header file, with all the method declarations, in the classes .cpp file with similar errors in the .cpp file as in the example above.
Could this be caused by a faulty insulation of Eclipse CDT, or of MinGW? Are there settings that I could change in Eclipse to designate where to look for its libraries (would that even help?)? Any help is GREATLY appreciated =).
Thanks!
I am getting this error when I try to use my project/module in my GOOGLE TESTS.
gcc.compile.c++ bin/gcc-4.8.3/debug/link-static/gmock_test.o
In file included from /usr/include/c++/4.8.2/tr1/functional:39:0,
from /usr/local/include/google/dense_hash_map:106,
from sagarmatha/utils/include/multicast_receiver.h:11,
from include/transmitter/mcx_receiver.h:25,
from src/unit_tests_theo.cpp:7:
/usr/include/c++/4.8.2/tr1/tuple:130:11: error: redefinition of ‘class std::tuple< <template-parameter-1-1> >’
class tuple : public _Tuple_impl<0, _Elements...>
^
In file included from /usr/include/c++/4.8.2/bits/stl_map.h:63:0,
from /usr/include/c++/4.8.2/map:61,
from 8k/include/Source.h:12,
from src/unit_tests_theo.cpp:2:
/usr/include/c++/4.8.2/tuple:388:11: error: previous definition of ‘class std::tuple< <template-parameter-1-1> >’
class tuple : public _Tuple_impl<0, _Elements...>
^
In file included from /usr/include/c++/4.8.2/tr1/functional:39:0,
from /usr/local/include/google/dense_hash_map:106,
from sagarmatha/utils/include/multicast_receiver.h:11,
from include/transmitter/mcx_receiver.h:25,
from src/unit_tests_theo.cpp:7:
/usr/include/c++/4.8.2/tr1/tuple:164:20: error: redefinition of ‘class std::tuple<>’
template<> class tuple<> { };
^
In file included from /usr/include/c++/4.8.2/bits/stl_map.h:63:0,
from /usr/include/c++/4.8.2/map:61,
from 8k/include/Source.h:12,
from src/unit_tests_theo.cpp:2:
/usr/include/c++/4.8.2/tuple:512:11: error: previous definition of ‘class std::tuple<>’
class tuple<>
^
In file included from /usr/include/c++/4.8.2/tr1/functional:39:0,
from /usr/local/include/google/dense_hash_map:106,
from sagarmatha/utils/include/multicast_receiver.h:11,
from include/transmitter/mcx_receiver.h:25,
from src/unit_tests_theo.cpp:7:
/usr/include/c++/4.8.2/tr1/tuple:168:11: error: redefinition of ‘class std::tuple<_T1, _T2>’
class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2>
^
In file included from /usr/include/c++/4.8.2/bits/stl_map.h:63:0,
from /usr/include/c++/4.8.2/map:61,
from 8k/include/Source.h:12,
from src/unit_tests_theo.cpp:2:
/usr/include/c++/4.8.2/tuple:521:11: error: previous definition of ‘class std::tuple<_T1, _T2>’
class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2>
^
In file included from /usr/include/c++/4.8.2/tuple:38:0,
from /usr/include/c++/4.8.2/bits/stl_map.h:63,
from /usr/include/c++/4.8.2/map:61,
from 8k/include/Source.h:12,
from src/unit_tests_theo.cpp:2:
/usr/include/c++/4.8.2/utility:83:24: error: template parameter ‘long unsigned int _Int’
template<std::size_t _Int, class _Tp>
^
In file included from /usr/include/c++/4.8.2/tr1/functional:39:0,
from /usr/local/include/google/dense_hash_map:106,
from sagarmatha/utils/include/multicast_receiver.h:11,
from include/transmitter/mcx_receiver.h:25,
from src/unit_tests_theo.cpp:7:
/usr/include/c++/4.8.2/tr1/tuple:223:12: error: redeclared here as ‘int __i’
struct tuple_element;
^
/usr/include/c++/4.8.2/tr1/tuple:230:12: error: specialization of ‘template<long unsigned int _Int, class _Tp> struct std::tuple_element’ in different namespace [-fpermissive]
struct tuple_element<__i, tuple<_Head, _Tail...> >
^
In file included from /usr/include/c++/4.8.2/tuple:38:0,
from /usr/include/c++/4.8.2/bits/stl_map.h:63,
from /usr/include/c++/4.8.2/map:61,
from 8k/include/Source.h:12,
from src/unit_tests_theo.cpp:2:
/usr/include/c++/4.8.2/utility:84:11: error: from definition of ‘template<long unsigned int _Int, class _Tp> struct std::tuple_element’ [-fpermissive]
class tuple_element;
^
In file included from /usr/include/c++/4.8.2/tr1/functional:39:0,
from /usr/local/include/google/dense_hash_map:106,
from sagarmatha/utils/include/multicast_receiver.h:11,
from include/transmitter/mcx_receiver.h:25,
from src/unit_tests_theo.cpp:7:
/usr/include/c++/4.8.2/tr1/tuple:237:12: error: redefinition of ‘struct std::tuple_element<0ul, std::tuple<_El0, _El ...> >’
struct tuple_element<0, tuple<_Head, _Tail...> >
^
In file included from /usr/include/c++/4.8.2/bits/stl_map.h:63:0,
from /usr/include/c++/4.8.2/map:61,
from 8k/include/Source.h:12,
from src/unit_tests_theo.cpp:2:
/usr/include/c++/4.8.2/tuple:687:12: error: previous definition of ‘struct std::tuple_element<0ul, std::tuple<_El0, _El ...> >’
struct tuple_element<0, tuple<_Head, _Tail...> >
^
In file included from /usr/include/c++/4.8.2/tr1/functional:39:0,
from /usr/local/include/google/dense_hash_map:106,
from sagarmatha/utils/include/multicast_receiver.h:11,
from include/transmitter/mcx_receiver.h:25,
from src/unit_tests_theo.cpp:7:
/usr/include/c++/4.8.2/tr1/tuple:248:12: error: redefinition of ‘struct std::tuple_size<std::tuple<_Args1 ...> >’
struct tuple_size<tuple<_Elements...> >
^
In file included from /usr/include/c++/4.8.2/bits/stl_map.h:63:0,
from /usr/include/c++/4.8.2/map:61,
from 8k/include/Source.h:12,
from src/unit_tests_theo.cpp:2:
/usr/include/c++/4.8.2/tuple:737:12: error: previous definition of ‘struct std::tuple_size<std::tuple<_Args1 ...> >’
struct tuple_size<tuple<_Elements...>>
^
In file included from /usr/include/c++/4.8.2/tr1/functional:39:0,
from /usr/local/include/google/dense_hash_map:106,
from sagarmatha/utils/include/multicast_receiver.h:11,
from include/transmitter/mcx_receiver.h:25,
from src/unit_tests_theo.cpp:7:
/usr/include/c++/4.8.2/tr1/tuple:254:49: error: definition of ‘std::tuple_size<std::tuple<_Args1 ...> >::value’ is not in namespace enclosing ‘std::tuple_size<std::tuple<_Args1 ...> >’ [-fpermissive]
const int tuple_size<tuple<_Elements...> >::value;
Is it related to map and dense_hash_map usage together ? Please help?
Since it solved your problem I'm making this an answer: set -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=0 to instruct the compilation not to use tr1 tuple nor its own tuple implementation.
As part of an MOC, I am implementing the merge_sort subroutine, and just for curiosity's sake, I would like to implement it using a function signature similar to what std::sort does.
The code I have so far is as follows.
#include <iostream>
#include <vector>
template <typename T>
bool read_number_list(const std::string& filename, std::vector<T>& output_array){
// ... read number list into an array
return true;
}
template<typename RandomAccessIterator>
void merge_sort_array (RandomAccessIterator first, RandomAccessIterator last, std::vector<decltype(*first)>& merge_array){
// ... merge routine
}
template<typename RandomAccessIterator>
void sort_array (RandomAccessIterator first, RandomAccessIterator last){
std::vector<decltype(*first)> merge_array;
merge_array.assign(first, last);
merge_sort_array(first, last, merge_array);
}
int main(){
std::vector<int> number_array;
read_number_list<int>("file.txt", number_array);
sort_array(number_array.begin(), number_array.end());
return 0;
}
I am seeing errors in the step where I make a copy of the array to be sorted, and also at the point where I invoke the merge_sort_array method. As is customary in templated code, I get the following plethora of errors (which I find quite inscrutable):
In file included from /usr/include/x86_64-linux-gnu/c++/4.8/bits/c++allocator.h:33:0,
from /usr/include/c++/4.8/bits/allocator.h:46,
from /usr/include/c++/4.8/string:41,
from /usr/include/c++/4.8/random:41,
from /usr/include/c++/4.8/bits/stl_algo.h:65,
from /usr/include/c++/4.8/algorithm:62,
from /home/balajeerc/Projects/algorithms/src/main/cpp/lib/algorithms/sorting/merge_sorter.h:8,
from /home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:1:
/usr/include/c++/4.8/ext/new_allocator.h: In instantiation of 'class __gnu_cxx::new_allocator<int&>':
/usr/include/c++/4.8/bits/allocator.h:92:11: required from 'class std::allocator<int&>'
/usr/include/c++/4.8/bits/alloc_traits.h:90:43: required from 'struct std::allocator_traits<std::allocator<int&> >'
/usr/include/c++/4.8/ext/alloc_traits.h:121:10: required from 'struct __gnu_cxx::__alloc_traits<std::allocator<int&> >'
/usr/include/c++/4.8/bits/stl_vector.h:75:28: required from 'struct std::_Vector_base<int&, std::allocator<int&> >'
/usr/include/c++/4.8/bits/stl_vector.h:210:11: required from 'class std::vector<int&, std::allocator<int&> >'
/home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:20:35: required from 'void sort_array(RandomAccessIterator, RandomAccessIterator) [with RandomAccessIterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >]'
/home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:34:56: required from here
/usr/include/c++/4.8/ext/new_allocator.h:63:26: error: forming pointer to reference type 'int&'
typedef _Tp* pointer;
^
/usr/include/c++/4.8/ext/new_allocator.h:64:26: error: forming pointer to reference type 'int&'
typedef const _Tp* const_pointer;
^
In file included from /usr/include/c++/4.8/string:41:0,
from /usr/include/c++/4.8/random:41,
from /usr/include/c++/4.8/bits/stl_algo.h:65,
from /usr/include/c++/4.8/algorithm:62,
from /home/balajeerc/Projects/algorithms/src/main/cpp/lib/algorithms/sorting/merge_sorter.h:8,
from /home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:1:
/usr/include/c++/4.8/bits/allocator.h: In instantiation of 'class std::allocator<int&>':
/usr/include/c++/4.8/bits/alloc_traits.h:90:43: required from 'struct std::allocator_traits<std::allocator<int&> >'
/usr/include/c++/4.8/ext/alloc_traits.h:121:10: required from 'struct __gnu_cxx::__alloc_traits<std::allocator<int&> >'
/usr/include/c++/4.8/bits/stl_vector.h:75:28: required from 'struct std::_Vector_base<int&, std::allocator<int&> >'
/usr/include/c++/4.8/bits/stl_vector.h:210:11: required from 'class std::vector<int&, std::allocator<int&> >'
/home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:20:35: required from 'void sort_array(RandomAccessIterator, RandomAccessIterator) [with RandomAccessIterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >]'
/home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:34:56: required from here
/usr/include/c++/4.8/bits/allocator.h:97:26: error: forming pointer to reference type 'int&'
typedef _Tp* pointer;
^
/usr/include/c++/4.8/bits/allocator.h:98:26: error: forming pointer to reference type 'int&'
typedef const _Tp* const_pointer;
^
In file included from /usr/include/c++/4.8/ext/alloc_traits.h:36:0,
from /usr/include/c++/4.8/bits/stl_construct.h:61,
from /usr/include/c++/4.8/bits/stl_tempbuf.h:60,
from /usr/include/c++/4.8/bits/stl_algo.h:62,
from /usr/include/c++/4.8/algorithm:62,
from /home/balajeerc/Projects/algorithms/src/main/cpp/lib/algorithms/sorting/merge_sorter.h:8,
from /home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:1:
/usr/include/c++/4.8/bits/alloc_traits.h: In instantiation of 'struct std::allocator_traits<std::allocator<int&> >':
/usr/include/c++/4.8/ext/alloc_traits.h:121:10: required from 'struct __gnu_cxx::__alloc_traits<std::allocator<int&> >'
/usr/include/c++/4.8/bits/stl_vector.h:75:28: required from 'struct std::_Vector_base<int&, std::allocator<int&> >'
/usr/include/c++/4.8/bits/stl_vector.h:210:11: required from 'class std::vector<int&, std::allocator<int&> >'
/home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:20:35: required from 'void sort_array(RandomAccessIterator, RandomAccessIterator) [with RandomAccessIterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >]'
/home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:34:56: required from here
/usr/include/c++/4.8/bits/alloc_traits.h:100:1: error: forming pointer to reference type 'std::allocator_traits<std::allocator<int&> >::value_type {aka int&}'
_GLIBCXX_ALLOC_TR_NESTED_TYPE(pointer, value_type*)
^
/usr/include/c++/4.8/bits/alloc_traits.h:100:1: error: no matching function for call to 'std::allocator_traits<std::allocator<int&> >::_S_pointer_helper(std::allocator<int&>*)'
_GLIBCXX_ALLOC_TR_NESTED_TYPE(pointer, value_type*)
^
/usr/include/c++/4.8/bits/alloc_traits.h:100:1: note: candidate is:
/usr/include/c++/4.8/bits/alloc_traits.h:100:1: note: template<class _Tp> static typename _Tp::pointer std::allocator_traits<_Alloc>::_S_pointer_helper(_Tp*) [with _Tp = _Tp; _Alloc = std::allocator<int&>]
_GLIBCXX_ALLOC_TR_NESTED_TYPE(pointer, value_type*)
^
/usr/include/c++/4.8/bits/alloc_traits.h:100:1: note: template argument deduction/substitution failed:
/usr/include/c++/4.8/bits/alloc_traits.h:109:1: error: no matching function for call to 'std::allocator_traits<std::allocator<int&> >::_S_const_pointer_helper(std::allocator<int&>*)'
_GLIBCXX_ALLOC_TR_NESTED_TYPE(const_pointer,
^
/usr/include/c++/4.8/bits/alloc_traits.h:109:1: note: candidate is:
/usr/include/c++/4.8/bits/alloc_traits.h:109:1: note: template<class _Tp> static typename _Tp::const_pointer std::allocator_traits<_Alloc>::_S_const_pointer_helper(_Tp*) [with _Tp = _Tp; _Alloc = std::allocator<int&>]
_GLIBCXX_ALLOC_TR_NESTED_TYPE(const_pointer,
^
/usr/include/c++/4.8/bits/alloc_traits.h:109:1: note: template argument deduction/substitution failed:
/usr/include/c++/4.8/bits/alloc_traits.h:120:1: error: no matching function for call to 'std::allocator_traits<std::allocator<int&> >::_S_void_pointer_helper(std::allocator<int&>*)'
_GLIBCXX_ALLOC_TR_NESTED_TYPE(void_pointer,
^
/usr/include/c++/4.8/bits/alloc_traits.h:120:1: note: candidate is:
/usr/include/c++/4.8/bits/alloc_traits.h:120:1: note: template<class _Tp> static typename _Tp::void_pointer std::allocator_traits<_Alloc>::_S_void_pointer_helper(_Tp*) [with _Tp = _Tp; _Alloc = std::allocator<int&>]
_GLIBCXX_ALLOC_TR_NESTED_TYPE(void_pointer,
^
/usr/include/c++/4.8/bits/alloc_traits.h:120:1: note: template argument deduction/substitution failed:
/usr/include/c++/4.8/bits/alloc_traits.h: In substitution of 'template<class _Tp> static typename _Tp::void_pointer std::allocator_traits<_Alloc>::_S_void_pointer_helper(_Tp*) [with _Tp = _Tp; _Alloc = std::allocator<int&>] [with _Tp = std::allocator<int&>]':
/usr/include/c++/4.8/bits/alloc_traits.h:120:1: required from 'struct std::allocator_traits<std::allocator<int&> >'
/usr/include/c++/4.8/ext/alloc_traits.h:121:10: required from 'struct __gnu_cxx::__alloc_traits<std::allocator<int&> >'
/usr/include/c++/4.8/bits/stl_vector.h:75:28: required from 'struct std::_Vector_base<int&, std::allocator<int&> >'
/usr/include/c++/4.8/bits/stl_vector.h:210:11: required from 'class std::vector<int&, std::allocator<int&> >'
/home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:20:35: required from 'void sort_array(RandomAccessIterator, RandomAccessIterator) [with RandomAccessIterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >]'
/home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:34:56: required from here
/usr/include/c++/4.8/bits/alloc_traits.h:120:1: error: no type named 'void_pointer' in 'class std::allocator<int&>'
/usr/include/c++/4.8/bits/alloc_traits.h: In instantiation of 'struct std::allocator_traits<std::allocator<int&> >':
/usr/include/c++/4.8/ext/alloc_traits.h:121:10: required from 'struct __gnu_cxx::__alloc_traits<std::allocator<int&> >'
/usr/include/c++/4.8/bits/stl_vector.h:75:28: required from 'struct std::_Vector_base<int&, std::allocator<int&> >'
/usr/include/c++/4.8/bits/stl_vector.h:210:11: required from 'class std::vector<int&, std::allocator<int&> >'
/home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:20:35: required from 'void sort_array(RandomAccessIterator, RandomAccessIterator) [with RandomAccessIterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >]'
/home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:34:56: required from here
/usr/include/c++/4.8/bits/alloc_traits.h:131:1: error: no matching function for call to 'std::allocator_traits<std::allocator<int&> >::_S_const_void_pointer_helper(std::allocator<int&>*)'
_GLIBCXX_ALLOC_TR_NESTED_TYPE(const_void_pointer,
^
/usr/include/c++/4.8/bits/alloc_traits.h:131:1: note: candidate is:
/usr/include/c++/4.8/bits/alloc_traits.h:131:1: note: template<class _Tp> static typename _Tp::const_void_pointer std::allocator_traits<_Alloc>::_S_const_void_pointer_helper(_Tp*) [with _Tp = _Tp; _Alloc = std::allocator<int&>]
_GLIBCXX_ALLOC_TR_NESTED_TYPE(const_void_pointer,
^
/usr/include/c++/4.8/bits/alloc_traits.h:131:1: note: template argument deduction/substitution failed:
/usr/include/c++/4.8/bits/alloc_traits.h: In substitution of 'template<class _Tp> static typename _Tp::const_void_pointer std::allocator_traits<_Alloc>::_S_const_void_pointer_helper(_Tp*) [with _Tp = _Tp; _Alloc = std::allocator<int&>] [with _Tp = std::allocator<int&>]':
/usr/include/c++/4.8/bits/alloc_traits.h:131:1: required from 'struct std::allocator_traits<std::allocator<int&> >'
/usr/include/c++/4.8/ext/alloc_traits.h:121:10: required from 'struct __gnu_cxx::__alloc_traits<std::allocator<int&> >'
/usr/include/c++/4.8/bits/stl_vector.h:75:28: required from 'struct std::_Vector_base<int&, std::allocator<int&> >'
/usr/include/c++/4.8/bits/stl_vector.h:210:11: required from 'class std::vector<int&, std::allocator<int&> >'
/home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:20:35: required from 'void sort_array(RandomAccessIterator, RandomAccessIterator) [with RandomAccessIterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >]'
/home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:34:56: required from here
/usr/include/c++/4.8/bits/alloc_traits.h:131:1: error: no type named 'const_void_pointer' in 'class std::allocator<int&>'
In file included from /usr/include/c++/4.8/bits/stl_construct.h:61:0,
from /usr/include/c++/4.8/bits/stl_tempbuf.h:60,
from /usr/include/c++/4.8/bits/stl_algo.h:62,
from /usr/include/c++/4.8/algorithm:62,
from /home/balajeerc/Projects/algorithms/src/main/cpp/lib/algorithms/sorting/merge_sorter.h:8,
from /home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:1:
/usr/include/c++/4.8/ext/alloc_traits.h: In instantiation of 'struct __gnu_cxx::__alloc_traits<std::allocator<int&> >':
/usr/include/c++/4.8/bits/stl_vector.h:75:28: required from 'struct std::_Vector_base<int&, std::allocator<int&> >'
/usr/include/c++/4.8/bits/stl_vector.h:210:11: required from 'class std::vector<int&, std::allocator<int&> >'
/home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:20:35: required from 'void sort_array(RandomAccessIterator, RandomAccessIterator) [with RandomAccessIterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >]'
/home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:34:56: required from here
/usr/include/c++/4.8/ext/alloc_traits.h:137:23: error: no members matching '__gnu_cxx::__alloc_traits<std::allocator<int&> >::_Base_type {aka std::allocator_traits<std::allocator<int&> >}::allocate' in '__gnu_cxx::__alloc_traits<std::allocator<int&> >::_Base_type {aka struct std::allocator_traits<std::allocator<int&> >}'
using _Base_type::allocate;
^
/usr/include/c++/4.8/ext/alloc_traits.h:138:23: error: no members matching '__gnu_cxx::__alloc_traits<std::allocator<int&> >::_Base_type {aka std::allocator_traits<std::allocator<int&> >}::deallocate' in '__gnu_cxx::__alloc_traits<std::allocator<int&> >::_Base_type {aka struct std::allocator_traits<std::allocator<int&> >}'
using _Base_type::deallocate;
^
In file included from /usr/include/c++/4.8/vector:64:0,
from /usr/include/c++/4.8/bits/random.h:34,
from /usr/include/c++/4.8/random:50,
from /usr/include/c++/4.8/bits/stl_algo.h:65,
from /usr/include/c++/4.8/algorithm:62,
from /home/balajeerc/Projects/algorithms/src/main/cpp/lib/algorithms/sorting/merge_sorter.h:8,
from /home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:1:
/usr/include/c++/4.8/bits/stl_vector.h: In instantiation of 'class std::vector<int&, std::allocator<int&> >':
/home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:20:35: required from 'void sort_array(RandomAccessIterator, RandomAccessIterator) [with RandomAccessIterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >]'
/home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:34:56: required from here
/usr/include/c++/4.8/bits/stl_vector.h:237:20: error: no members matching 'std::vector<int&, std::allocator<int&> >::_Base {aka std::_Vector_base<int&, std::allocator<int&> >}::_M_allocate' in 'std::vector<int&, std::allocator<int&> >::_Base {aka struct std::_Vector_base<int&, std::allocator<int&> >}'
using _Base::_M_allocate;
^
/usr/include/c++/4.8/bits/stl_vector.h:238:20: error: no members matching 'std::vector<int&, std::allocator<int&> >::_Base {aka std::_Vector_base<int&, std::allocator<int&> >}::_M_deallocate' in 'std::vector<int&, std::allocator<int&> >::_Base {aka struct std::_Vector_base<int&, std::allocator<int&> >}'
using _Base::_M_deallocate;
^
/usr/include/c++/4.8/bits/stl_vector.h:878:7: error: forming pointer to reference type 'int&'
data() _GLIBCXX_NOEXCEPT
^
/usr/include/c++/4.8/bits/stl_vector.h:886:7: error: forming pointer to reference type 'int&'
data() const _GLIBCXX_NOEXCEPT
^
/usr/include/c++/4.8/bits/stl_vector.h:919:7: error: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int&; _Alloc = std::allocator<int&>; std::vector<_Tp, _Alloc>::value_type = int&]' cannot be overloaded
push_back(value_type&& __x)
^
/usr/include/c++/4.8/bits/stl_vector.h:901:7: error: with 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int&; _Alloc = std::allocator<int&>; std::vector<_Tp, _Alloc>::value_type = int&]'
push_back(const value_type& __x)
^
/home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc: In instantiation of 'void sort_array(RandomAccessIterator, RandomAccessIterator) [with RandomAccessIterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >]':
/home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:34:56: required from here
/home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:22:46: error: 'merge_sort_array' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
merge_sort_array(first, last, merge_array);
^
/home/balajeerc/Projects/algorithms/src/test/cpp/lib/algorithms/sorting/test_inversion_count.cc:26:6: note: 'template<class RandomAccessIterator> void merge_sort_array(RandomAccessIterator, RandomAccessIterator, std::vector<decltype (* first)>&)' declared here, later in the translation unit
void merge_sort_array (RandomAccessIterator first, RandomAccessIterator last, std::vector<decltype(*first)>& merge_array){
^
make[2]: *** [src/test/cpp/lib/algorithms/sorting/CMakeFiles/test_inversion_count.dir/test_inversion_count.cc.o] Error 1
make[1]: *** [src/test/cpp/lib/algorithms/sorting/CMakeFiles/test_inversion_count.dir/all] Error 2
make: *** [all] Error 2
What am I doing wrong?
Your problem is the misuse of decltype:
decltype( expression )
yields T& for lvalue expressions of type T, and you cannot have an std::vector<int&>. Thus the error.
To fix that, use typename std::iterator_traits<RandomAccessIterator>::value_type as template parameter instead.