模板:<bits/_Complex.h>

本文分享了一个用于快速傅立叶变换的手写复数类模板,对比系统自带的complex类,该模板在性能上表现更优。文章详细介绍了模板的使用方法及各种运算符的重载实现。

作死去学了FFT。。。

系统自带的complex真是慢。。。比手写的慢了整整0.8s。。。于是果断手写了一发Complex的模板。。。。

原型:

template<typename T>class Complex;

使用方法:

using namespace PoPoQQQ_Complex;
	Complex<double> x;cin>>x;
	x+=Complex<double>(1,0);
	x-=Complex<double>(0,1);
	x*=Complex<double>(2,3);
	x/=Complex<double>(2);
	if( x==Complex<double>(3.500000003,2) )//重载==与!=,自带精度判断 
		cout<<x<<endl;
	cout<<Abs(x)<<endl;//模值 
	cout<<Arg(x)<<endl;//极角
	cout<<Norm(x)<<endl;//模值的平方
	cout<<Conj(x)<<endl;//共轭复数
	cout<<Exp(x)<<endl;//自然对数
	cout<<Log(x)<<endl;//自然对数底的对数
	cout<<Pow(x,10)<<endl;//幂
	cout<<Sqrt(x)<<endl;//平方根 

代码:

//writen by PoPoQQQ
//not finished yet
#define _COMPLEX_

#ifndef _MATH_
#include<cmath>
#endif

#ifndef _GLIBCXX_IOSTREAM
#include<iostream>
#endif

#ifndef EPS
#define EPS 1e-7
#endif

namespace PoPoQQQ_Complex{
	using namespace std;
	template<typename T>class Complex{
	public:
		T real,imaginary;
		Complex() {}
		Complex(T _,T __=0.0):real(_),imaginary(__) {}
		Complex& operator += (const Complex<T> &x) { real+=x.real;imaginary+=x.imaginary;return *this; }
		Complex& operator -= (const Complex<T> &x) { real-=x.real;imaginary-=x.imaginary;return *this; }
		Complex& operator *= (const T &x) { real*=x;imaginary*=x;return *this; }
		Complex& operator /= (const T &x) { real/=x;imaginary/=x;return *this; }
		friend Complex operator + (const Complex<T> &x,const Complex<T> &y) { Complex re=x;re+=y;return re; }
		friend Complex operator - (const Complex<T> &x,const Complex<T> &y) { Complex re=x;re-=y;return re; }
		friend Complex operator * (const Complex<T> &x,const T y) { Complex re=x;re*=y;return re; }
		friend Complex operator / (const Complex<T> &x,const T y) { Complex re=x;re/=y;return re; }
		friend Complex operator * (const Complex<T> &x,const Complex<T> &y)
		{ return Complex(x.real*y.real-x.imaginary*y.imaginary,x.real*y.imaginary+x.imaginary*y.real); }
		friend Complex operator / (const Complex<T> &x,const Complex<T> &y)
		{ return x*Complex(y.real,-y.imaginary)/(y.real*y.real+y.imaginary*y.imaginary); }
		Complex& operator *= (const Complex &x) { return *this=(*this)*x; }
		Complex& operator /= (const Complex &x) { return *this=(*this)/x; }
		bool operator == (const Complex &x) { return fabs(real-x.real)<EPS && fabs(imaginary-x.imaginary)<EPS; }
		bool operator != (const Complex &x) { return fabs(real-x.real)>EPS || fabs(imaginary-x.imaginary)>EPS; }
		friend istream& operator >> (istream& _is,Complex &x) { _is>>x.real>>x.imaginary;return _is; }
		friend ostream& operator << (ostream& _os,const Complex &x) { _os<<'('<<x.real<<','<<x.imaginary<<')';return _os; }
		friend T Abs(const Complex<T> &x) { return sqrt(x.real*x.real+x.imaginary*x.imaginary); }
		friend T Arg(const Complex<T> &x) { return atan2(x.imaginary,x.real); }
		friend T Norm(const Complex<T> &x) { return x.real*x.real+x.imaginary*x.imaginary; }
		friend Complex<T> Conj(const Complex<T> &x) { return Complex(x.real,-x.imaginary); }
		friend Complex<T> Exp(const Complex<T> &x) { return exp(x.real)*Complex<T>(cos(x.imaginary),sin(x.imaginary)); }
		friend Complex<T> Log(const Complex<T> &x) { return Complex<T>(log(Norm(x))/2.0,atan2(x.imaginary,x.real)); }
		friend Complex<T> Pow(const Complex<T> &x,const T y) { return Exp(y*Log(x)); }
		friend Complex<T> Sqrt(const Complex<T> &x) { return Pow(x,0.5); }
	};
}


In file included from prog_joined.cpp:1: In file included from ./precompiled/headers.h:25: In file included from /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/ccomplex:39: In file included from /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/complex:45: In file included from /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/sstream:40: In file included from /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/istream:40: In file included from /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/ios:44: In file included from /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/ios_base.h:41: In file included from /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/locale_classes.h:40: In file included from /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/string:54: In file included from /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/basic_string.h:39: In file included from /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/ext/alloc_traits.h:34: /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/alloc_traits.h:536:4: error: no matching function for call to 'construct_at' 527 | std::construct_at(__p, std::forward<_Args>(__args)...); | ^~~~~~~~~~~~~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/vector.tcc:117:21: note: in instantiation of function template specialization 'std::allocator_traits<std::allocator<std::vector<int>>>::construct<std::vector<int>, int (&)[2]>' requested here 108 | _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, | ^ Line 18: Char 17: note: in instantiation of function template specialization 'std::vector<std::vector<int>>::emplace_back<int (&)[2]>' requested here 18 | ans.emplace_back(num); | ^ /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/stl_construct.h:94:5: note: candidate template ignored: substitution failure [with _Tp = std::vector<int>, _Args = <int (&)[2]>]: no matching constructor for initialization of 'std::vector<int>' 85 | construct_at(_Tp* __location, _Args&&... __args) | ^ 86 | noexcept(noexcept(::new((void*)0) _Tp(std::declval<_Args>()...))) 87 | -> decltype(::new((void*)0) _Tp(std::declval<_Args>()...)) | ~~~ 1 error generated.
08-02
a.cpp: In function ‘int main()’: a.cpp:7:16: error: no match for ‘operator>>’ (operand types are ‘std::basic_istream<char>::__istream_type’ {aka ‘std::basic_istream<char>’} and ‘<unresolved overloaded function type>’) 7 | cin>>number>>endl; | ~~~~~~~~~~~^~~~~~ In file included from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from a.cpp:1: /usr/include/c++/11/istream:120:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__istream_type& (*)(std::basic_istream<_CharT, _Traits>::__istream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 120 | operator>>(__istream_type& (*__pf)(__istream_type&)) | ^~~~~~~~ /usr/include/c++/11/istream:120:36: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘std::basic_istream<char>::__istream_type& (*)(std::basic_istream<char>::__istream_type&)’ {aka ‘std::basic_istream<char>& (*)(std::basic_istream<char>&)’} 120 | operator>>(__istream_type& (*__pf)(__istream_type&)) | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/11/istream:124:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__ios_type& (*)(std::basic_istream<_CharT, _Traits>::__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>; std::basic_istream<_CharT, _Traits>::__ios_type = std::basic_ios<char>]’ 124 | operator>>(__ios_type& (*__pf)(__ios_type&)) | ^~~~~~~~ /usr/include/c++/11/istream:124:32: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘std::basic_istream<char>::__ios_type& (*)(std::basic_istream<char>::__ios_type&)’ {aka ‘std::basic_ios<char>& (*)(std::basic_ios<char>&)’} 124 | operator>>(__ios_type& (*__pf)(__ios_type&)) | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~ /usr/include/c++/11/istream:131:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 131 | operator>>(ios_base& (*__pf)(ios_base&)) | ^~~~~~~~ /usr/include/c++/11/istream:131:30: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘std::ios_base& (*)(std::ios_base&)’ 131 | operator>>(ios_base& (*__pf)(ios_base&)) | ~~~~~~~~~~~~^~~~~~~~~~~~~~~~ /usr/include/c++/11/istream:168:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 168 | operator>>(bool& __n) | ^~~~~~~~ /usr/include/c++/11/istream:168:24: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘bool&’ 168 | operator>>(bool& __n) | ~~~~~~^~~ /usr/include/c++/11/istream:172:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]’ 172 | operator>>(short& __n); | ^~~~~~~~ /usr/include/c++/11/istream:172:25: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘short int&’ 172 | operator>>(short& __n); | ~~~~~~~^~~ /usr/include/c++/11/istream:175:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 175 | operator>>(unsigned short& __n) | ^~~~~~~~ /usr/include/c++/11/istream:175:34: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘short unsigned int&’ 175 | operator>>(unsigned short& __n) | ~~~~~~~~~~~~~~~~^~~ /usr/include/c++/11/istream:179:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]’ 179 | operator>>(int& __n); | ^~~~~~~~ /usr/include/c++/11/istream:179:23: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘int&’ 179 | operator>>(int& __n); | ~~~~~^~~ /usr/include/c++/11/istream:182:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 182 | operator>>(unsigned int& __n) | ^~~~~~~~ /usr/include/c++/11/istream:182:32: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘unsigned int&’ 182 | operator>>(unsigned int& __n) | ~~~~~~~~~~~~~~^~~ /usr/include/c++/11/istream:186:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 186 | operator>>(long& __n) | ^~~~~~~~ /usr/include/c++/11/istream:186:24: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘long int&’ 186 | operator>>(long& __n) | ~~~~~~^~~ /usr/include/c++/11/istream:190:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 190 | operator>>(unsigned long& __n) | ^~~~~~~~ /usr/include/c++/11/istream:190:33: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘long unsigned int&’ 190 | operator>>(unsigned long& __n) | ~~~~~~~~~~~~~~~^~~ /usr/include/c++/11/istream:195:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 195 | operator>>(long long& __n) | ^~~~~~~~ /usr/include/c++/11/istream:195:29: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘long long int&’ 195 | operator>>(long long& __n) | ~~~~~~~~~~~^~~ /usr/include/c++/11/istream:199:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 199 | operator>>(unsigned long long& __n) | ^~~~~~~~ /usr/include/c++/11/istream:199:38: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘long long unsigned int&’ 199 | operator>>(unsigned long long& __n) | ~~~~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/11/istream:214:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 214 | operator>>(float& __f) | ^~~~~~~~ /usr/include/c++/11/istream:214:25: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘float&’ 214 | operator>>(float& __f) | ~~~~~~~^~~ /usr/include/c++/11/istream:218:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 218 | operator>>(double& __f) | ^~~~~~~~ /usr/include/c++/11/istream:218:26: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘double&’ 218 | operator>>(double& __f) | ~~~~~~~~^~~ /usr/include/c++/11/istream:222:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 222 | operator>>(long double& __f) | ^~~~~~~~ /usr/include/c++/11/istream:222:31: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘long double&’ 222 | operator>>(long double& __f) | ~~~~~~~~~~~~~^~~ /usr/include/c++/11/istream:235:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 235 | operator>>(void*& __p) | ^~~~~~~~ /usr/include/c++/11/istream:235:25: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘void*&’ 235 | operator>>(void*& __p) | ~~~~~~~^~~ /usr/include/c++/11/istream:259:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__streambuf_type*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>]’ 259 | operator>>(__streambuf_type* __sb); | ^~~~~~~~ /usr/include/c++/11/istream:259:36: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘std::basic_istream<char>::__streambuf_type*’ {aka ‘std::basic_streambuf<char>*’} 259 | operator>>(__streambuf_type* __sb); | ~~~~~~~~~~~~~~~~~~^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:45, from a.cpp:1: /usr/include/c++/11/cstddef:132:5: note: candidate: ‘template<class _IntegerType> constexpr std::__byte_op_t<_IntegerType> std::operator>>(std::byte, _IntegerType)’ 132 | operator>>(byte __b, _IntegerType __shift) noexcept | ^~~~~~~~ /usr/include/c++/11/cstddef:132:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_IntegerType’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/string:56, from /usr/include/c++/11/bits/locale_classes.h:40, from /usr/include/c++/11/bits/ios_base.h:41, from /usr/include/c++/11/ios:42, from /usr/include/c++/11/istream:38, from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from a.cpp:1: /usr/include/c++/11/bits/basic_string.tcc:1485:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&)’ 1485 | operator>>(basic_istream<_CharT, _Traits>& __in, | ^~~~~~~~ /usr/include/c++/11/bits/basic_string.tcc:1485:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_Alloc’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/istream:1016, from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from a.cpp:1: /usr/include/c++/11/bits/istream.tcc:958:5: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, _CharT&) [with _CharT = char; _Traits = std::char_traits<char>]’ 958 | operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c) | ^~~~~~~~ /usr/include/c++/11/bits/istream.tcc:958:62: note: no known conversion for argument 2 from ‘<unresolved overloaded function type>’ to ‘char&’ 958 | operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c) | ~~~~~~~~^~~ In file included from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from a.cpp:1: /usr/include/c++/11/istream:756:5: note: candidate: ‘template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, unsigned char&)’ 756 | operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c) | ^~~~~~~~ /usr/include/c++/11/istream:756:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘unsigned char&’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from a.cpp:1: /usr/include/c++/11/istream:761:5: note: candidate: ‘template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, signed char&)’ 761 | operator>>(basic_istream<char, _Traits>& __in, signed char& __c) | ^~~~~~~~ /usr/include/c++/11/istream:761:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘signed char&’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from a.cpp:1: /usr/include/c++/11/istream:859:5: note: candidate: ‘template<class _CharT, class _Traits, long unsigned int _Num> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, _CharT (&)[_Num])’ 859 | operator>>(basic_istream<_CharT, _Traits>& __in, _CharT (&__s)[_Num]) | ^~~~~~~~ /usr/include/c++/11/istream:859:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_Num’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from a.cpp:1: /usr/include/c++/11/istream:868:5: note: candidate: ‘template<class _Traits, long unsigned int _Num> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, unsigned char (&)[_Num])’ 868 | operator>>(basic_istream<char, _Traits>& __in, unsigned char (&__s)[_Num]) | ^~~~~~~~ /usr/include/c++/11/istream:868:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_Num’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from a.cpp:1: /usr/include/c++/11/istream:873:5: note: candidate: ‘template<class _Traits, long unsigned int _Num> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, signed char (&)[_Num])’ 873 | operator>>(basic_istream<char, _Traits>& __in, signed char (&__s)[_Num]) | ^~~~~~~~ /usr/include/c++/11/istream:873:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_Num’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from a.cpp:1: /usr/include/c++/11/istream:1006:5: note: candidate: ‘template<class _Istream, class _Tp> _Istream&& std::operator>>(_Istream&&, _Tp&&)’ 1006 | operator>>(_Istream&& __is, _Tp&& __x) | ^~~~~~~~ /usr/include/c++/11/istream:1006:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_Tp’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from a.cpp:1: /usr/include/c++/11/complex:501:5: note: candidate: ‘template<class _Tp, class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::complex<_Tp>&)’ 501 | operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x) | ^~~~~~~~ /usr/include/c++/11/complex:501:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_Tp’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:66, from a.cpp:1: /usr/include/c++/11/bitset:1472:5: note: candidate: ‘template<class _CharT, class _Traits, long unsigned int _Nb> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::bitset<_Nb>&)’ 1472 | operator>>(std::basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x) | ^~~~~~~~ /usr/include/c++/11/bitset:1472:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_Nb’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:72, from a.cpp:1: /usr/include/c++/11/iomanip:71:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Resetiosflags)’ 71 | operator>>(basic_istream<_CharT, _Traits>& __is, _Resetiosflags __f) | ^~~~~~~~ /usr/include/c++/11/iomanip:71:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘std::_Resetiosflags’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:72, from a.cpp:1: /usr/include/c++/11/iomanip:101:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setiosflags)’ 101 | operator>>(basic_istream<_CharT, _Traits>& __is, _Setiosflags __f) | ^~~~~~~~ /usr/include/c++/11/iomanip:101:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘std::_Setiosflags’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:72, from a.cpp:1: /usr/include/c++/11/iomanip:132:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setbase)’ 132 | operator>>(basic_istream<_CharT, _Traits>& __is, _Setbase __f) | ^~~~~~~~ /usr/include/c++/11/iomanip:132:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘std::_Setbase’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:72, from a.cpp:1: /usr/include/c++/11/iomanip:170:5: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setfill<_CharT>) [with _CharT = char; _Traits = std::char_traits<char>]’ 170 | operator>>(basic_istream<_CharT, _Traits>& __is, _Setfill<_CharT> __f) | ^~~~~~~~ /usr/include/c++/11/iomanip:170:71: note: no known conversion for argument 2 from ‘<unresolved overloaded function type>’ to ‘std::_Setfill<char>’ 170 | operator>>(basic_istream<_CharT, _Traits>& __is, _Setfill<_CharT> __f) | ~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/11/iomanip:200:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setprecision)’ 200 | operator>>(basic_istream<_CharT, _Traits>& __is, _Setprecision __f) | ^~~~~~~~ /usr/include/c++/11/iomanip:200:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘std::_Setprecision’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:72, from a.cpp:1: /usr/include/c++/11/iomanip:230:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setw)’ 230 | operator>>(basic_istream<_CharT, _Traits>& __is, _Setw __f) | ^~~~~~~~ /usr/include/c++/11/iomanip:230:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘std::_Setw’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:72, from a.cpp:1: /usr/include/c++/11/iomanip:264:5: note: candidate: ‘template<class _CharT, class _Traits, class _MoneyT> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Get_money<_MoneyT>)’ 264 | operator>>(basic_istream<_CharT, _Traits>& __is, _Get_money<_MoneyT> __f) | ^~~~~~~~ /usr/include/c++/11/iomanip:264:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_MoneyT’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:72, from a.cpp:1: /usr/include/c++/11/iomanip:418:5: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Get_time<_CharT>) [with _CharT = char; _Traits = std::char_traits<char>]’ 418 | operator>>(basic_istream<_CharT, _Traits>& __is, _Get_time<_CharT> __f) | ^~~~~~~~ /usr/include/c++/11/iomanip:418:72: note: no known conversion for argument 2 from ‘<unresolved overloaded function type>’ to ‘std::_Get_time<char>’ 418 | operator>>(basic_istream<_CharT, _Traits>& __is, _Get_time<_CharT> __f) | ~~~~~~~~~~~~~~~~~~^~~ In file included from /usr/include/c++/11/valarray:603, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95, from a.cpp:1: /usr/include/c++/11/bits/valarray_after.h:414:5: note: candidate: ‘template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__shift_right, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__shift_right, typename _Dom1::value_type>::result_type> std::operator>>(const std::_Expr<_Dom1, typename _Dom1::value_type>&, const std::_Expr<_Dom2, typename _Dom2::value_type>&)’ 414 | _DEFINE_EXPR_BINARY_OPERATOR(>>, struct std::__shift_right) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/11/bits/valarray_after.h:414:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: ‘std::basic_istream<char>::__istream_type’ {aka ‘std::basic_istream<char>’} is not derived from ‘const std::_Expr<_Dom1, typename _Dom1::value_type>’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/valarray:603, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95, from a.cpp:1: /usr/include/c++/11/bits/valarray_after.h:414:5: note: candidate: ‘template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__shift_right, std::_Expr, std::_Constant, _Dom, typename _Dom::value_type>, typename std::__fun<std::__shift_right, typename _Dom1::value_type>::result_type> std::operator>>(const std::_Expr<_Dom1, typename _Dom1::value_type>&, const typename _Dom::value_type&)’ 414 | _DEFINE_EXPR_BINARY_OPERATOR(>>, struct std::__shift_right) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/11/bits/valarray_after.h:414:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: ‘std::basic_istream<char>::__istream_type’ {aka ‘std::basic_istream<char>’} is not derived from ‘const std::_Expr<_Dom1, typename _Dom1::value_type>’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/valarray:603, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95, from a.cpp:1: /usr/include/c++/11/bits/valarray_after.h:414:5: note: candidate: ‘template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__shift_right, std::_Constant, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__shift_right, typename _Dom1::value_type>::result_type> std::operator>>(const typename _Dom::value_type&, const std::_Expr<_Dom1, typename _Dom1::value_type>&)’ 414 | _DEFINE_EXPR_BINARY_OPERATOR(>>, struct std::__shift_right) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/11/bits/valarray_after.h:414:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_Dom’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/valarray:603, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95, from a.cpp:1: /usr/include/c++/11/bits/valarray_after.h:414:5: note: candidate: ‘template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__shift_right, std::_Expr, std::_ValArray, _Dom, typename _Dom::value_type>, typename std::__fun<std::__shift_right, typename _Dom1::value_type>::result_type> std::operator>>(const std::_Expr<_Dom1, typename _Dom1::value_type>&, const std::valarray<typename _Dom::value_type>&)’ 414 | _DEFINE_EXPR_BINARY_OPERATOR(>>, struct std::__shift_right) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/11/bits/valarray_after.h:414:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: ‘std::basic_istream<char>::__istream_type’ {aka ‘std::basic_istream<char>’} is not derived from ‘const std::_Expr<_Dom1, typename _Dom1::value_type>’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/valarray:603, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95, from a.cpp:1: /usr/include/c++/11/bits/valarray_after.h:414:5: note: candidate: ‘template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__shift_right, std::_ValArray, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__shift_right, typename _Dom1::value_type>::result_type> std::operator>>(const std::valarray<typename _Dom::value_type>&, const std::_Expr<_Dom1, typename _Dom1::value_type>&)’ 414 | _DEFINE_EXPR_BINARY_OPERATOR(>>, struct std::__shift_right) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/11/bits/valarray_after.h:414:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_Dom’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95, from a.cpp:1: /usr/include/c++/11/valarray:1195:1: note: candidate: ‘template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__shift_right, std::_ValArray, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__shift_right, _Tp>::result_type> std::operator>>(const std::valarray<_Tp>&, const std::valarray<_Tp>&)’ 1195 | _DEFINE_BINARY_OPERATOR(>>, __shift_right) | ^~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/11/valarray:1195:1: note: template argument deduction/substitution failed: a.cpp:7:18: note: ‘std::basic_istream<char>::__istream_type’ {aka ‘std::basic_istream<char>’} is not derived from ‘const std::valarray<_Tp>’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95, from a.cpp:1: /usr/include/c++/11/valarray:1195:1: note: candidate: ‘template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__shift_right, std::_ValArray, std::_Constant, _Tp, _Tp>, typename std::__fun<std::__shift_right, _Tp>::result_type> std::operator>>(const std::valarray<_Tp>&, const typename std::valarray<_Tp>::value_type&)’ 1195 | _DEFINE_BINARY_OPERATOR(>>, __shift_right) | ^~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/11/valarray:1195:1: note: template argument deduction/substitution failed: a.cpp:7:18: note: ‘std::basic_istream<char>::__istream_type’ {aka ‘std::basic_istream<char>’} is not derived from ‘const std::valarray<_Tp>’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95, from a.cpp:1: /usr/include/c++/11/valarray:1195:1: note: candidate: ‘template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__shift_right, std::_Constant, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__shift_right, _Tp>::result_type> std::operator>>(const typename std::valarray<_Tp>::value_type&, const std::valarray<_Tp>&)’ 1195 | _DEFINE_BINARY_OPERATOR(>>, __shift_right) | ^~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/11/valarray:1195:1: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_Tp’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/random:51, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:108, from a.cpp:1: /usr/include/c++/11/bits/random.tcc:921:5: note: candidate: ‘template<class _IntType, class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::uniform_int_distribution<_IntType>&)’ 921 | operator>>(std::basic_istream<_CharT, _Traits>& __is, | ^~~~~~~~ /usr/include/c++/11/bits/random.tcc:921:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_IntType’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/random:51, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:108, from a.cpp:1: /usr/include/c++/11/bits/random.tcc:982:5: note: candidate: ‘template<class _RealType, class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::uniform_real_distribution<_IntType>&)’ 982 | operator>>(std::basic_istream<_CharT, _Traits>& __is, | ^~~~~~~~ /usr/include/c++/11/bits/random.tcc:982:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_RealType’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/random:51, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:108, from a.cpp:1: /usr/include/c++/11/bits/random.tcc:2167:5: note: candidate: ‘template<class _RealType, class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::cauchy_distribution<_RealType>&)’ 2167 | operator>>(std::basic_istream<_CharT, _Traits>& __is, | ^~~~~~~~ /usr/include/c++/11/bits/random.tcc:2167:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_RealType’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/random:49, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:108, from a.cpp:1: /usr/include/c++/11/bits/random.h:3722:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::bernoulli_distribution&)’ 3722 | operator>>(std::basic_istream<_CharT, _Traits>& __is, | ^~~~~~~~ /usr/include/c++/11/bits/random.h:3722:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘std::bernoulli_distribution&’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/random:51, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:108, from a.cpp:1: /usr/include/c++/11/bits/random.tcc:1124:5: note: candidate: ‘template<class _IntType, class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::geometric_distribution<_IntType>&)’ 1124 | operator>>(std::basic_istream<_CharT, _Traits>& __is, | ^~~~~~~~ /usr/include/c++/11/bits/random.tcc:1124:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_IntType’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/random:51, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:108, from a.cpp:1: /usr/include/c++/11/bits/random.tcc:1775:5: note: candidate: ‘template<class _RealType, class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::exponential_distribution<_RealType>&)’ 1775 | operator>>(std::basic_istream<_CharT, _Traits>& __is, | ^~~~~~~~ /usr/include/c++/11/bits/random.tcc:1775:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_RealType’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/random:51, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:108, from a.cpp:1: /usr/include/c++/11/bits/random.tcc:2561:5: note: candidate: ‘template<class _RealType, class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::weibull_distribution<_RealType>&)’ 2561 | operator>>(std::basic_istream<_CharT, _Traits>& __is, | ^~~~~~~~教我怎么看编译错误的原因
最新发布
10-20
#include <iostream> #include <fstream> #include <vector> #include <Eigen/Core> #include <Eigen/Geometry> #include <g2o/core/base_vertex.h> #include <g2o/core/base_binary_edge.h> #include <g2o/core/base_unary_edge.h> #include <g2o/core/block_solver.h> #include <g2o/core/optimization_algorithm_levenberg.h> #include <g2o/solvers/dense/linear_solver_dense.h> #include <g2o/types/slam3d/vertex_se3.h> #include <g2o/types/slam3d/edge_se3.h> #include <g2o/core/eigen_types.h> #include <g2o/types/slam3d/types_slam3d.h> #include <opencv2/opencv.hpp> using namespace std; using namespace Eigen; struct Edge { size_t s; // Start index size_t e; // End index Isometry3d pose; // Relative pose between start and end }; class INS { public: void optimizeTrajectory(std::vector<Isometry3d> &poses) { std::vector<Edge> edgeData; for (size_t i = 0; i < poses.size() - 1; ++i) { Edge edge_data; edge_data.s = i; edge_data.e = i + 1; edge_data.pose = poses[i].inverse() * poses[i + 1]; edgeData.push_back(edge_data); } // 添加最后一个点到第一个点的边 Edge edge_data; edge_data.s = poses.size() - 1; // 最后一个点的索引 edge_data.e = 0; // 第一个点的索引 Isometry3d error_pose = poses[edge_data.s]; Isometry3d true_pose = error_pose * calibration_error_.Get(); LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); edge_data.pose = true_pose.inverse() * poses[edge_data.e]; edgeData.push_back(edge_data); std::unique_ptr<g2o::LinearSolverDense<g2o::BlockSolverX::PoseMatrixType>> linearSolver = std::make_unique<g2o::LinearSolverDense<g2o::BlockSolverX::PoseMatrixType>>(); g2o::OptimizationAlgorithmLevenberg *solver = new g2o::OptimizationAlgorithmLevenberg( std::make_unique<g2o::BlockSolverX>(std::move(linearSolver))); g2o::SparseOptimizer optimizer; optimizer.setAlgorithm(solver); optimizer.setVerbose(false); for (int i = 0; i < poses.size(); i++) { g2o::VertexSE3 *v = new g2o::VertexSE3(); v->setId(i); v->setEstimate(poses[i]); if (i == 0) { v->setFixed(true); } optimizer.addVertex(v); } for (const auto &pData : edgeData) { g2o::EdgeSE3 *edge = new g2o::EdgeSE3(); edge->setVertex(0, optimizer.vertex(pData.s)); edge->setVertex(1, optimizer.vertex(pData.e)); if (&pData == &edgeData.back()) { LogWarn("*******&pData == &edgeData.back()************"); edge->setInformation(Matrix6d::Identity() * 100000); } else { edge->setInformation(Matrix6d::Identity() * 0.001); } edge->setMeasurement(pData.pose); optimizer.addEdge(edge); } optimizer.initializeOptimization(); optimizer.optimize(500); for (int i = 0; i < poses.size(); i++) { g2o::VertexSE3 *vertex = dynamic_cast<g2o::VertexSE3 *>(optimizer.vertex(i)); poses[i] = vertex->estimate(); } LogWarn("Trajectory optimization successful !!!!!!!!!!"); } private: struct CalibrationError { Isometry3d Get() const { Isometry3d calib; calib.setIdentity(); calib.translate(Vector3d(0.1, 0.1, 0.1)); // Example calibration error calib.rotate(AngleAxisd(Deg2Rad(0.1), Vector3d::UnitZ())); // Example rotation error return calib; } }; double Deg2Rad(double deg) const { return deg * M_PI / 180.0; } CalibrationError calibration_error_; template<typename T> void LogInfo(const T& message) { cout << "[INFO] " << message << endl; } template<typename T> void LogWarn(const T& message) { cout << "[WARN] " << message << endl; } string matrixToString(const Matrix4d& matrix) { stringstream ss; ss << matrix; return ss.str(); } }; void generateSimulatedTrajectory(std::vector<Isometry3d>& poses, int numPoints) { double sideLength = 4.0; // 正方形的边长 double angleStep = INS().Deg2Rad(90.0); // 每个转角的角度 for (int i = 0; i < numPoints; ++i) { Isometry3d pose = Isometry3d::Identity(); switch (i % 4) { case 0: pose.translation() = Vector3d(sideLength * (i / 4), 0, 0); break; case 1: pose.translation() = Vector3d(sideLength * (i / 4 + 1), 0, 0); pose.rotate(AngleAxisd(angleStep, Vector3d::UnitZ())); break; case 2: pose.translation() = Vector3d(sideLength * (i / 4 + 1), sideLength, 0); pose.rotate(AngleAxisd(angleStep * 2, Vector3d::UnitZ())); break; case 3: pose.translation() = Vector3d(sideLength * (i / 4), sideLength, 0); pose.rotate(AngleAxisd(angleStep * 3, Vector3d::UnitZ())); break; } // 加入误差 pose.translate(Vector3d(rand() / double(RAND_MAX) * 0.1, rand() / double(RAND_MAX) * 0.1, rand() / double(RAND_MAX) * 0.1)); pose.rotate(AngleAxisd(INS().Deg2Rad(rand() % 2), Vector3d::UnitZ())); poses.push_back(pose); } } void drawTrajectory(const std::vector<Isometry3d>& poses, const std::string& title) { cv::Mat img(800, 800, CV_8UC3, cv::Scalar(255, 255, 255)); for (size_t i = 0; i < poses.size(); ++i) { Vector3d pos = poses[i].translation(); if (i > 0) { Vector3d prevPos = poses[i-1].translation(); cv::line(img, cv::Point((prevPos.x() + 4.0) * 100, (-prevPos.y() + 4.0) * 100), cv::Point((pos.x() + 4.0) * 100, (-pos.y() + 4.0) * 100), cv::Scalar(0, 255, 0), 2); } cv::circle(img, cv::Point((pos.x() + 4.0) * 100, (-pos.y() + 4.0) * 100), 3, cv::Scalar(0, 0, 0), -1); } cv::imshow(title, img); cv::waitKey(1); } int main() { srand(time(NULL)); int numTrajectoryPoints = 16; // 轨迹点数量(正方形的四个角重复四次) std::vector<Isometry3d> trajectory(numTrajectoryPoints); // 生成模拟轨迹 generateSimulatedTrajectory(trajectory, numTrajectoryPoints); // 显示优化前的轨迹 drawTrajectory(trajectory, "Before Optimization"); // 创建INS对象并进行优化 INS ins_optimizer; ins_optimizer.optimizeTrajectory(trajectory); // 显示优化后的轨迹 drawTrajectory(trajectory, "After Optimization"); cv::waitKey(0); return 0; } 报错:/usr/include/c++/9/ostream:523:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /usr/include/c++/9/iostream:39, from /home/guo/g2o仿真/src/optimize.cc:1: /usr/include/c++/9/ostream:528:5: note: candidate: ‘template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, unsigned char)’ 528 | operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c) | ^~~~~~~~ /usr/include/c++/9/ostream:528:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /usr/include/c++/9/iostream:39, from /home/guo/g2o仿真/src/optimize.cc:1: /usr/include/c++/9/ostream:548:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const _CharT*)’ 548 | operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s) | ^~~~~~~~ /usr/include/c++/9/ostream:548:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /usr/include/c++/9/ostream:702, from /usr/include/c++/9/iostream:39, from /home/guo/g2o仿真/src/optimize.cc:1: /usr/include/c++/9/bits/ostream.tcc:321:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const char*)’ 321 | operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s) | ^~~~~~~~ /usr/include/c++/9/bits/ostream.tcc:321:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /usr/include/c++/9/iostream:39, from /home/guo/g2o仿真/src/optimize.cc:1: /usr/include/c++/9/ostream:565:5: note: candidate: ‘template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const char*)’ 565 | operator<<(basic_ostream<char, _Traits>& __out, const char* __s) | ^~~~~~~~ /usr/include/c++/9/ostream:565:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /usr/include/c++/9/iostream:39, from /home/guo/g2o仿真/src/optimize.cc:1: /usr/include/c++/9/ostream:578:5: note: candidate: ‘template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const signed char*)’ 578 | operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s) | ^~~~~~~~ /usr/include/c++/9/ostream:578:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /usr/include/c++/9/iostream:39, from /home/guo/g2o仿真/src/optimize.cc:1: /usr/include/c++/9/ostream:583:5: note: candidate: ‘template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const unsigned char*)’ 583 | operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s) | ^~~~~~~~ /usr/include/c++/9/ostream:583:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /usr/include/c++/9/iostream:39, from /home/guo/g2o仿真/src/optimize.cc:1: /usr/include/c++/9/ostream:691:5: note: candidate: ‘template<class _Ostream, class _Tp> typename std::enable_if<std::__and_<std::__not_<std::is_lvalue_reference<_Tp> >, std::__is_convertible_to_basic_ostream<_Ostream>, std::__is_insertable<typename std::__is_convertible_to_basic_ostream<_Tp>::__ostream_type, const _Tp&, void> >::value, typename std::__is_convertible_to_basic_ostream<_Tp>::__ostream_type>::type std::operator<<(_Ostream&&, const _Tp&)’ 691 | operator<<(_Ostream&& __os, const _Tp& __x) | ^~~~~~~~ /usr/include/c++/9/ostream:691:5: note: template argument deduction/substitution failed: /usr/include/c++/9/ostream: In substitution of ‘template<class _Ostream, class _Tp> typename std::enable_if<std::__and_<std::__not_<std::is_lvalue_reference<_Tp> >, std::__is_convertible_to_basic_ostream<_Ostream>, std::__is_insertable<typename std::__is_convertible_to_basic_ostream<_Tp>::__ostream_type, const _Tp&, void> >::value, typename std::__is_convertible_to_basic_ostream<_Tp>::__ostream_type>::type std::operator<<(_Ostream&&, const _Tp&) [with _Ostream = const char (&)[32]; _Tp = std::__cxx11::basic_string<char>]’: /home/guo/g2o仿真/src/optimize.cc:46:103: required from here /usr/include/c++/9/ostream:691:5: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’ In file included from /usr/local/include/eigen3/Eigen/Core:50, from /home/guo/g2o仿真/src/optimize.cc:4: /usr/include/c++/9/complex:552:5: note: candidate: ‘template<class _Tp, class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::complex<_Tp>&)’ 552 | operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x) | ^~~~~~~~ /usr/include/c++/9/complex:552:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /opt/ros/noetic/include/g2o/core/hyper_graph.h:31, from /opt/ros/noetic/include/g2o/core/optimizable_graph.h:35, from /opt/ros/noetic/include/g2o/core/base_vertex.h:30, from /home/guo/g2o仿真/src/optimize.cc:6: /usr/include/c++/9/bitset:1538:5: note: candidate: ‘template<class _CharT, class _Traits, long unsigned int _Nb> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::bitset<_Nb>&)’ 1538 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, | ^~~~~~~~ /usr/include/c++/9/bitset:1538:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /usr/include/c++/9/memory:81, from /opt/ros/noetic/include/g2o/core/robust_kernel.h:30, from /opt/ros/noetic/include/g2o/core/base_binary_edge.h:34, from /home/guo/g2o仿真/src/optimize.cc:7: /usr/include/c++/9/bits/shared_ptr.h:66:5: note: candidate: ‘template<class _Ch, class _Tr, class _Tp, __gnu_cxx::_Lock_policy _Lp> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::__shared_ptr<_Tp, _Lp>&)’ 66 | operator<<(std::basic_ostream<_Ch, _Tr>& __os, | ^~~~~~~~ /usr/include/c++/9/bits/shared_ptr.h:66:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /opt/ros/noetic/include/g2o/core/sparse_block_matrix.h:34, from /opt/ros/noetic/include/g2o/core/solver.h:31, from /opt/ros/noetic/include/g2o/core/block_solver.h:31, from /home/guo/g2o仿真/src/optimize.cc:9: /usr/include/c++/9/iomanip:79:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Resetiosflags)’ 79 | operator<<(basic_ostream<_CharT, _Traits>& __os, _Resetiosflags __f) | ^~~~~~~~ /usr/include/c++/9/iomanip:79:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /opt/ros/noetic/include/g2o/core/sparse_block_matrix.h:34, from /opt/ros/noetic/include/g2o/core/solver.h:31, from /opt/ros/noetic/include/g2o/core/block_solver.h:31, from /home/guo/g2o仿真/src/optimize.cc:9: /usr/include/c++/9/iomanip:109:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setiosflags)’ 109 | operator<<(basic_ostream<_CharT, _Traits>& __os, _Setiosflags __f) | ^~~~~~~~ /usr/include/c++/9/iomanip:109:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /opt/ros/noetic/include/g2o/core/sparse_block_matrix.h:34, from /opt/ros/noetic/include/g2o/core/solver.h:31, from /opt/ros/noetic/include/g2o/core/block_solver.h:31, from /home/guo/g2o仿真/src/optimize.cc:9: /usr/include/c++/9/iomanip:143:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setbase)’ 143 | operator<<(basic_ostream<_CharT, _Traits>& __os, _Setbase __f) | ^~~~~~~~ /usr/include/c++/9/iomanip:143:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /opt/ros/noetic/include/g2o/core/sparse_block_matrix.h:34, from /opt/ros/noetic/include/g2o/core/solver.h:31, from /opt/ros/noetic/include/g2o/core/block_solver.h:31, from /home/guo/g2o仿真/src/optimize.cc:9: /usr/include/c++/9/iomanip:178:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setfill<_CharT>)’ 178 | operator<<(basic_ostream<_CharT, _Traits>& __os, _Setfill<_CharT> __f) | ^~~~~~~~ /usr/include/c++/9/iomanip:178:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /opt/ros/noetic/include/g2o/core/sparse_block_matrix.h:34, from /opt/ros/noetic/include/g2o/core/solver.h:31, from /opt/ros/noetic/include/g2o/core/block_solver.h:31, from /home/guo/g2o仿真/src/optimize.cc:9: /usr/include/c++/9/iomanip:208:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setprecision)’ 208 | operator<<(basic_ostream<_CharT, _Traits>& __os, _Setprecision __f) | ^~~~~~~~ /usr/include/c++/9/iomanip:208:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /opt/ros/noetic/include/g2o/core/sparse_block_matrix.h:34, from /opt/ros/noetic/include/g2o/core/solver.h:31, from /opt/ros/noetic/include/g2o/core/block_solver.h:31, from /home/guo/g2o仿真/src/optimize.cc:9: /usr/include/c++/9/iomanip:238:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setw)’ 238 | operator<<(basic_ostream<_CharT, _Traits>& __os, _Setw __f) | ^~~~~~~~ /usr/include/c++/9/iomanip:238:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /opt/ros/noetic/include/g2o/core/sparse_block_matrix.h:34, from /opt/ros/noetic/include/g2o/core/solver.h:31, from /opt/ros/noetic/include/g2o/core/block_solver.h:31, from /home/guo/g2o仿真/src/optimize.cc:9: /usr/include/c++/9/iomanip:311:5: note: candidate: ‘template<class _CharT, class _Traits, class _MoneyT> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Put_money<_MoneyT>)’ 311 | operator<<(basic_ostream<_CharT, _Traits>& __os, _Put_money<_MoneyT> __f) | ^~~~~~~~ /usr/include/c++/9/iomanip:311:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /opt/ros/noetic/include/g2o/core/sparse_block_matrix.h:34, from /opt/ros/noetic/include/g2o/core/solver.h:31, from /opt/ros/noetic/include/g2o/core/block_solver.h:31, from /home/guo/g2o仿真/src/optimize.cc:9: /usr/include/c++/9/iomanip:363:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Put_time<_CharT>)’ 363 | operator<<(basic_ostream<_CharT, _Traits>& __os, _Put_time<_CharT> __f) | ^~~~~~~~ /usr/include/c++/9/iomanip:363:5: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [32]’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ In file included from /usr/local/include/eigen3/Eigen/Core:269, from /home/guo/g2o仿真/src/optimize.cc:4: /usr/local/include/eigen3/Eigen/src/Core/IO.h:249:16: note: candidate: ‘template<class Derived> std::ostream& Eigen::operator<<(std::ostream&, const Eigen::DenseBase<Derived>&)’ 249 | std::ostream & operator << | ^~~~~~~~ /usr/local/include/eigen3/Eigen/src/Core/IO.h:249:16: note: template argument deduction/substitution failed: /home/guo/g2o仿真/src/optimize.cc:46:103: note: ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} is not derived from ‘const Eigen::DenseBase<Derived>’ 46 | LogInfo("The map optimization error is:\n" << matrixToString(calibration_error_.Get().matrix())); | ^ /home/guo/g2o仿真/src/optimize.cc:77:38: error: ‘Matrix6d’ has not been declared 77 | edge->setInformation(Matrix6d::Identity() * 100000); | ^~~~~~~~ /home/guo/g2o仿真/src/optimize.cc:79:38: error: ‘Matrix6d’ has not been declared 79 | edge->setInformation(Matrix6d::Identity() * 0.001); | ^~~~~~~~ /home/guo/g2o仿真/src/optimize.cc: In member function ‘Eigen::Isometry3d INS::CalibrationError::Get() const’: /home/guo/g2o仿真/src/optimize.cc:101:48: error: cannot call member function ‘double INS::Deg2Rad(double) const’ without object 101 | calib.rotate(AngleAxisd(Deg2Rad(0.1), Vector3d::UnitZ())); // Example rotation error | ^ /home/guo/g2o仿真/src/optimize.cc: In function ‘void generateSimulatedTrajectory(std::vector<Eigen::Transform<double, 3, 1> >&, int)’: /home/guo/g2o仿真/src/optimize.cc:131:42: error: ‘double INS::Deg2Rad(double) const’ is private within this context 131 | double angleStep = INS().Deg2Rad(90.0); // 每个转角的角度 | ^ /home/guo/g2o仿真/src/optimize.cc:106:12: note: declared private here 106 | double Deg2Rad(double deg) const { | ^~~~~~~ /home/guo/g2o仿真/src/optimize.cc:146:56: error: ‘double INS::Deg2Rad(double) const’ is private within this context 146 | pose.rotate(AngleAxisd(INS().Deg2Rad(rand() % 2), Vector3d::UnitZ())); | ^ /home/guo/g2o仿真/src/optimize.cc:106:12: note: declared private here 106 | double Deg2Rad(double deg) const { | ^~~~~~~ make[2]: *** [CMakeFiles/g2o_demo.dir/build.make:76:CMakeFiles/g2o_demo.dir/optimize.cc.o] 错误 1 make[1]: *** [CMakeFiles/Makefile2:673:CMakeFiles/g2o_demo.dir/all] 错误 2 make: *** [Makefile:146:all] 错误 2 给出完整修改后代码
08-03
编译失败 main.cpp: In function 'int main()': main.cpp:19:34: error: no matching function for call to 'min(int&, long long int&)' 19 | int x= min(k,c[i]); | ^ In file included from /usr/include/c++/9/bits/char_traits.h:39, from /usr/include/c++/9/ios:40, from /usr/include/c++/9/istream:38, from /usr/include/c++/9/sstream:38, from /usr/include/c++/9/complex:45, from /usr/include/c++/9/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54, from main.cpp:1: /usr/include/c++/9/bits/stl_algobase.h:198:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)' 198 | min(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/9/bits/stl_algobase.h:198:5: note: template argument deduction/substitution failed: main.cpp:19:34: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int') 19 | int x= min(k,c[i]); | ^ In file included from /usr/include/c++/9/bits/char_traits.h:39, from /usr/include/c++/9/ios:40, from /usr/include/c++/9/istream:38, from /usr/include/c++/9/sstream:38, from /usr/include/c++/9/complex:45, from /usr/include/c++/9/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54, from main.cpp:1: /usr/include/c++/9/bits/stl_algobase.h:246:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)' 246 | min(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/9/bits/stl_algobase.h:246:5: note: template argument deduction/substitution failed: main.cpp:19:34: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int') 19 | int x= min(k,c[i]); | ^ In file included from /usr/include/c++/9/algorithm:62, from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65, from main.cpp:1: /usr/include/c++/9/bits/stl_algo.h:3450:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)' 3450 | min(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/9/bits/stl_algo.h:3450:5: note: template argument deduction/substitution failed: main.cpp:19:34: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 19 | int x= min(k,c[i]); | ^ In file included from /usr/include/c++/9/algorithm:62, from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65, from main.cpp:1: /usr/include/c++/9/bits/stl_algo.h:3456:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)' 3456 | min(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/9/bits/stl_algo.h:3456:5: note: template argument deduction/substitution failed: main.cpp:19:34: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 19 | int x= min(k,c[i]); | ^
07-23
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值