I try to make a simple sum of two objects and I skip error took time trying to solve it.
Complejo.cpp
#include "Complejo.h"
Complejo::Complejo(double real, double complejo)
{
this->real = real;
this->complejo = complejo;
};
Complejo operator+(Complejo a, Complejo b)
{
Complejo temporal(0.0, 0.0);
temporal.real = a.real + b.real;
temporal.complejo = a.complejo + b.complejo;;
return temporal;
};
Complejo.h
#ifndef COMPLEJO_H_
#define COMPLEJO_H_
class Complejo
{
public:
Complejo(double, double);
double real;
double complejo;
};
#endif
test_complejo.cpp
#include <iostream>
#include "Complejo.h"
using namespace std;
int main()
{
Complejo unNumeroComplejo(43.5, 56.4);
Complejo otroNumeroComplejo(34.5, 45.6);
Complejo suma = unNumeroComplejo + otroNumeroComplejo;
cout << "hola mundo" << endl;
return 0;
};
Error
03:14:49 **** Incremental Build of configuration Debug for project teoriaCatedraCalvo ****
make all
Building file: ../sobrecargaDeOperadores/Complejo.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"sobrecargaDeOperadores/Complejo.d" -MT"sobrecargaDeOperadores/Complejo.o" -o "sobrecargaDeOperadores/Complejo.o" "../sobrecargaDeOperadores/Complejo.cpp"
Finished building: ../sobrecargaDeOperadores/Complejo.cpp
Building file: ../sobrecargaDeOperadores/test_complejo.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"sobrecargaDeOperadores/test_complejo.d" -MT"sobrecargaDeOperadores/test_complejo.o" -o "sobrecargaDeOperadores/test_complejo.o" "../sobrecargaDeOperadores/test_complejo.cpp"
../sobrecargaDeOperadores/test_complejo.cpp: In function ‘int main()’:
../sobrecargaDeOperadores/test_complejo.cpp:9:35: error: no match for ‘operator+’ (operand types are ‘Complejo’ and ‘Complejo’)
Complejo suma = unNumeroComplejo + otroNumeroComplejo;
~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
from /usr/include/c++/7/bits/char_traits.h:39,
from /usr/include/c++/7/ios:40,
from /usr/include/c++/7/ostream:38,
from /usr/include/c++/7/iostream:39,
from ../sobrecargaDeOperadores/test_complejo.cpp:1:
/usr/include/c++/7/bits/stl_iterator.h:397:5: note: candidate: template<class _Iterator> std::reverse_iterator<_Iterator> std::operator+(typename std::reverse_iterator<_Iterator>::difference_type, const std::reverse_iterator<_Iterator>&)
operator+(typename reverse_iterator<_Iterator>::difference_type __n,
^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:397:5: note: template argument deduction/substitution failed:
../sobrecargaDeOperadores/test_complejo.cpp:9:37: note: ‘Complejo’ is not derived from ‘const std::reverse_iterator<_Iterator>’
Complejo suma = unNumeroComplejo + otroNumeroComplejo;
^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
from /usr/include/c++/7/bits/char_traits.h:39,
from /usr/include/c++/7/ios:40,
from /usr/include/c++/7/ostream:38,
from /usr/include/c++/7/iostream:39,
from ../sobrecargaDeOperadores/test_complejo.cpp:1:
/usr/include/c++/7/bits/stl_iterator.h:1198:5: note: candidate: template<class _Iterator> std::move_iterator<_IteratorL> std::operator+(typename std::move_iterator<_IteratorL>::difference_type, const std::move_iterator<_IteratorL>&)
operator+(typename move_iterator<_Iterator>::difference_type __n,
^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:1198:5: note: template argument deduction/substitution failed:
../sobrecargaDeOperadores/test_complejo.cpp:9:37: note: ‘Complejo’ is not derived from ‘const std::move_iterator<_IteratorL>’
Complejo suma = unNumeroComplejo + otroNumeroComplejo;
^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/string:52:0,
from /usr/include/c++/7/bits/locale_classes.h:40,
from /usr/include/c++/7/bits/ios_base.h:41,
from /usr/include/c++/7/ios:42,
from /usr/include/c++/7/ostream:38,
from /usr/include/c++/7/iostream:39,
from ../sobrecargaDeOperadores/test_complejo.cpp:1:
/usr/include/c++/7/bits/basic_string.h:5876:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^~~~~~~~
/usr/include/c++/7/bits/basic_string.h:5876:5: note: template argument deduction/substitution failed:
../sobrecargaDeOperadores/test_complejo.cpp:9:37: note: ‘Complejo’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
Complejo suma = unNumeroComplejo + otroNumeroComplejo;
^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/string:53:0,
from /usr/include/c++/7/bits/locale_classes.h:40,
from /usr/include/c++/7/bits/ios_base.h:41,
from /usr/include/c++/7/ios:42,
from /usr/include/c++/7/ostream:38,
from /usr/include/c++/7/iostream:39,
from ../sobrecargaDeOperadores/test_complejo.cpp:1:
/usr/include/c++/7/bits/basic_string.tcc:1157:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const _CharT*, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
operator+(const _CharT* __lhs,
^~~~~~~~
/usr/include/c++/7/bits/basic_string.tcc:1157:5: note: template argument deduction/substitution failed:
../sobrecargaDeOperadores/test_complejo.cpp:9:37: note: mismatched types ‘const _CharT*’ and ‘Complejo’
Complejo suma = unNumeroComplejo + otroNumeroComplejo;
^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/string:53:0,
from /usr/include/c++/7/bits/locale_classes.h:40,
from /usr/include/c++/7/bits/ios_base.h:41,
from /usr/include/c++/7/ios:42,
from /usr/include/c++/7/ostream:38,
from /usr/include/c++/7/iostream:39,
from ../sobrecargaDeOperadores/test_complejo.cpp:1:
/usr/include/c++/7/bits/basic_string.tcc:1173:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(_CharT, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
operator+(_CharT __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs)
^~~~~~~~
/usr/include/c++/7/bits/basic_string.tcc:1173:5: note: template argument deduction/substitution failed:
../sobrecargaDeOperadores/test_complejo.cpp:9:37: note: ‘Complejo’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
Complejo suma = unNumeroComplejo + otroNumeroComplejo;
^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/string:52:0,
from /usr/include/c++/7/bits/locale_classes.h:40,
from /usr/include/c++/7/bits/ios_base.h:41,
from /usr/include/c++/7/ios:42,
from /usr/include/c++/7/ostream:38,
from /usr/include/c++/7/iostream:39,
from ../sobrecargaDeOperadores/test_complejo.cpp:1:
/usr/include/c++/7/bits/basic_string.h:5913:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^~~~~~~~
/usr/include/c++/7/bits/basic_string.h:5913:5: note: template argument deduction/substitution failed:
../sobrecargaDeOperadores/test_complejo.cpp:9:37: note: ‘Complejo’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
Complejo suma = unNumeroComplejo + otroNumeroComplejo;
^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/string:52:0,
from /usr/include/c++/7/bits/locale_classes.h:40,
from /usr/include/c++/7/bits/ios_base.h:41,
from /usr/include/c++/7/ios:42,
from /usr/include/c++/7/ostream:38,
from /usr/include/c++/7/iostream:39,
from ../sobrecargaDeOperadores/test_complejo.cpp:1:
/usr/include/c++/7/bits/basic_string.h:5929:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, _CharT)
operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
^~~~~~~~
/usr/include/c++/7/bits/basic_string.h:5929:5: note: template argument deduction/substitution failed:
../sobrecargaDeOperadores/test_complejo.cpp:9:37: note: ‘Complejo’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
Complejo suma = unNumeroComplejo + otroNumeroComplejo;
^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/string:52:0,
from /usr/include/c++/7/bits/locale_classes.h:40,
from /usr/include/c++/7/bits/ios_base.h:41,
from /usr/include/c++/7/ios:42,
from /usr/include/c++/7/ostream:38,
from /usr/include/c++/7/iostream:39,
from ../sobrecargaDeOperadores/test_complejo.cpp:1:
/usr/include/c++/7/bits/basic_string.h:5941:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
^~~~~~~~
/usr/include/c++/7/bits/basic_string.h:5941:5: note: template argument deduction/substitution failed:
../sobrecargaDeOperadores/test_complejo.cpp:9:37: note: ‘Complejo’ is not derived from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
Complejo suma = unNumeroComplejo + otroNumeroComplejo;
^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/string:52:0,
from /usr/include/c++/7/bits/locale_classes.h:40,
from /usr/include/c++/7/bits/ios_base.h:41,
from /usr/include/c++/7/ios:42,
from /usr/include/c++/7/ostream:38,
from /usr/include/c++/7/iostream:39,
from ../sobrecargaDeOperadores/test_complejo.cpp:1:
/usr/include/c++/7/bits/basic_string.h:5947:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&)
operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^~~~~~~~
/usr/include/c++/7/bits/basic_string.h:5947:5: note: template argument deduction/substitution failed:
../sobrecargaDeOperadores/test_complejo.cpp:9:37: note: ‘Complejo’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
Complejo suma = unNumeroComplejo + otroNumeroComplejo;
^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/string:52:0,
from /usr/include/c++/7/bits/locale_classes.h:40,
from /usr/include/c++/7/bits/ios_base.h:41,
from /usr/include/c++/7/ios:42,
from /usr/include/c++/7/ostream:38,
from /usr/include/c++/7/iostream:39,
from ../sobrecargaDeOperadores/test_complejo.cpp:1:
/usr/include/c++/7/bits/basic_string.h:5953:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&)
operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
^~~~~~~~
/usr/include/c++/7/bits/basic_string.h:5953:5: note: template argument deduction/substitution failed:
../sobrecargaDeOperadores/test_complejo.cpp:9:37: note: ‘Complejo’ is not derived from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
Complejo suma = unNumeroComplejo + otroNumeroComplejo;
^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/string:52:0,
from /usr/include/c++/7/bits/locale_classes.h:40,
from /usr/include/c++/7/bits/ios_base.h:41,
from /usr/include/c++/7/ios:42,
from /usr/include/c++/7/ostream:38,
from /usr/include/c++/7/iostream:39,
from ../sobrecargaDeOperadores/test_complejo.cpp:1:
/usr/include/c++/7/bits/basic_string.h:5965:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const _CharT*, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&)
operator+(const _CharT* __lhs,
^~~~~~~~
/usr/include/c++/7/bits/basic_string.h:5965:5: note: template argument deduction/substitution failed:
../sobrecargaDeOperadores/test_complejo.cpp:9:37: note: mismatched types ‘const _CharT*’ and ‘Complejo’
Complejo suma = unNumeroComplejo + otroNumeroComplejo;
^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/string:52:0,
from /usr/include/c++/7/bits/locale_classes.h:40,
from /usr/include/c++/7/bits/ios_base.h:41,
from /usr/include/c++/7/ios:42,
from /usr/include/c++/7/ostream:38,
from /usr/include/c++/7/iostream:39,
from ../sobrecargaDeOperadores/test_complejo.cpp:1:
/usr/include/c++/7/bits/basic_string.h:5971:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(_CharT, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&)
operator+(_CharT __lhs,
^~~~~~~~
/usr/include/c++/7/bits/basic_string.h:5971:5: note: template argument deduction/substitution failed:
../sobrecargaDeOperadores/test_complejo.cpp:9:37: note: ‘Complejo’ is not derived from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
Complejo suma = unNumeroComplejo + otroNumeroComplejo;
^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/string:52:0,
from /usr/include/c++/7/bits/locale_classes.h:40,
from /usr/include/c++/7/bits/ios_base.h:41,
from /usr/include/c++/7/ios:42,
from /usr/include/c++/7/ostream:38,
from /usr/include/c++/7/iostream:39,
from ../sobrecargaDeOperadores/test_complejo.cpp:1:
/usr/include/c++/7/bits/basic_string.h:5977:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, const _CharT*)
operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
^~~~~~~~
/usr/include/c++/7/bits/basic_string.h:5977:5: note: template argument deduction/substitution failed:
../sobrecargaDeOperadores/test_complejo.cpp:9:37: note: ‘Complejo’ is not derived from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
Complejo suma = unNumeroComplejo + otroNumeroComplejo;
^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/string:52:0,
from /usr/include/c++/7/bits/locale_classes.h:40,
from /usr/include/c++/7/bits/ios_base.h:41,
from /usr/include/c++/7/ios:42,
from /usr/include/c++/7/ostream:38,
from /usr/include/c++/7/iostream:39,
from ../sobrecargaDeOperadores/test_complejo.cpp:1:
/usr/include/c++/7/bits/basic_string.h:5983:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, _CharT)
operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
^~~~~~~~
/usr/include/c++/7/bits/basic_string.h:5983:5: note: template argument deduction/substitution failed:
../sobrecargaDeOperadores/test_complejo.cpp:9:37: note: ‘Complejo’ is not derived from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
Complejo suma = unNumeroComplejo + otroNumeroComplejo;
^~~~~~~~~~~~~~~~~~
../sobrecargaDeOperadores/test_complejo.cpp:9:11: warning: unused variable ‘suma’ [-Wunused-variable]
Complejo suma = unNumeroComplejo + otroNumeroComplejo;
^~~~
make: *** [sobrecargaDeOperadores/test_complejo.o] Error 1
sobrecargaDeOperadores/subdir.mk:21: recipe for target 'sobrecargaDeOperadores/test_complejo.o' failed
03:14:50 Build Finished (took 1s.218ms)