Formalnie dodałem tylko stringa do tego kodu bo wcześniej nie zawarłem:
#include <iostream>
#include <string>
using namespace std;
class wektor{
double x, y, z;
public:
wektor(double X = 0., double Y = 0., double Z = 0., string = ""){
x = X;
y = Y;
z = Z;
double getX(){return x;}
double getY(){return y;}
double getZ(){return z;}
string getNazwa();
}
};
ostream& operator<<(ostream& strumien, wektor& w){
strumien << "(" << w.getX() << ", " << w.getY() << ", " << w.getZ() << ", " << w.getNazwa() << ")";
return strumien;
}
wektor w1(-1., -1., -1, "Globalny");
int main()
{
wektor w1(1., -2., 1., "Lokalny");
cout << w1 << endl;
cout << ::w1 << endl;
cout << "Suma wektorow - " << w1 + ::w1 << endl;
if(w1 * ::w1 == 0) cout << "Wektory są prostopadłe";
else cout << "Wektory nie są prostopadłe";
return 0;
}
tylko pojawiają się takie błędy na wyjściu:
main.cpp: In constructor ‘wektor::wektor(double, double, double, std::string)’:
main.cpp:22:16: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
22 | double getX(){return x;}
| ^~
main.cpp:22:16: note: remove parentheses to default-initialize a variable
22 | double getX(){return x;}
| ^~
| --
main.cpp:22:16: note: or replace parentheses with braces to value-initialize a variable
main.cpp:22:18: error: a function-definition is not allowed here before ‘{’ token
22 | double getX(){return x;}
| ^
main.cpp:23:16: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
23 | double getY(){return y;}
| ^~
main.cpp:23:16: note: remove parentheses to default-initialize a variable
23 | double getY(){return y;}
| ^~
| --
main.cpp:23:16: note: or replace parentheses with braces to value-initialize a variable
main.cpp:23:18: error: a function-definition is not allowed here before ‘{’ token
23 | double getY(){return y;}
| ^
main.cpp:24:16: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
24 | double getZ(){return z;}
| ^~
main.cpp:24:16: note: remove parentheses to default-initialize a variable
24 | double getZ(){return z;}
| ^~
| --
main.cpp:24:16: note: or replace parentheses with braces to value-initialize a variable
main.cpp:24:18: error: a function-definition is not allowed here before ‘{’ token
24 | double getZ(){return z;}
| ^
main.cpp:25:20: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
25 | string getNazwa();
| ^~
main.cpp:25:20: note: remove parentheses to default-initialize a variable
25 | string getNazwa();
| ^~
| --
main.cpp: In function ‘std::ostream& operator<<(std::ostream&, wektor&)’:
main.cpp:30:26: error: ‘class wektor’ has no member named ‘getX’
30 | strumien << "(" << w.getX() << ", " << w.getY() << ", " << w.getZ() << ", " << w.getNazwa() << ")";
| ^~~~
main.cpp:30:46: error: ‘class wektor’ has no member named ‘getY’
30 | strumien << "(" << w.getX() << ", " << w.getY() << ", " << w.getZ() << ", " << w.getNazwa() << ")";
| ^~~~
main.cpp:30:66: error: ‘class wektor’ has no member named ‘getZ’
30 | strumien << "(" << w.getX() << ", " << w.getY() << ", " << w.getZ() << ", " << w.getNazwa() << ")";
| ^~~~
main.cpp:30:86: error: ‘class wektor’ has no member named ‘getNazwa’
30 | strumien << "(" << w.getX() << ", " << w.getY() << ", " << w.getZ() << ", " << w.getNazwa() << ")";
| ^~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:40:38: error: no match for ‘operator+’ (operand types are ‘wektor’ and ‘wektor’)
40 | cout << "Suma wektorow - " << w1 + ::w1 << endl;
| ~~ ^ ~~~~
| | |
| wektor wektor
In file included from /usr/include/c++/11/bits/stl_algobase.h:67,
from /usr/include/c++/11/bits/char_traits.h:39,
from /usr/include/c++/11/ios:40,
from /usr/include/c++/11/ostream:38,
from /usr/include/c++/11/iostream:39,
from main.cpp:9:
/usr/include/c++/11/bits/stl_iterator.h:568:5: note: candidate: ‘template std::reverse_iterator<_Iterator> std::operator+(typename std::reverse_iterator<_Iterator>::difference_type, const std::reverse_iterator<_Iterator>&)’
568 | operator+(typename reverse_iterator<_Iterator>::difference_type __n,
| ^~~~~~~~
/usr/include/c++/11/bits/stl_iterator.h:568:5: note: template argument deduction/substitution failed:
main.cpp:40:42: note: ‘wektor’ is not derived from ‘const std::reverse_iterator<_Iterator>’
40 | cout << "Suma wektorow - " << w1 + ::w1 << endl;
| ^~
In file included from /usr/include/c++/11/bits/stl_algobase.h:67,
from /usr/include/c++/11/bits/char_traits.h:39,
from /usr/include/c++/11/ios:40,
from /usr/include/c++/11/ostream:38,
from /usr/include/c++/11/iostream:39,
from main.cpp:9:
/usr/include/c++/11/bits/stl_iterator.h:1646:5: note: candidate: ‘template std::move_iterator<_IteratorL> std::operator+(typename std::move_iterator<_IteratorL>::difference_type, const std::move_iterator<_IteratorL>&)’
1646 | operator+(typename move_iterator<_Iterator>::difference_type __n,
| ^~~~~~~~
/usr/include/c++/11/bits/stl_iterator.h:1646:5: note: template argument deduction/substitution failed:
main.cpp:40:42: note: ‘wektor’ is not derived from ‘const std::move_iterator<_IteratorL>’
40 | cout << "Suma wektorow - " << w1 + ::w1 << endl;
| ^~
In file included from /usr/include/c++/11/string:55,
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/ostream:38,
from /usr/include/c++/11/iostream:39,
from main.cpp:9:
/usr/include/c++/11/bits/basic_string.h:6095:5: note: candidate: ‘template 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>&)’
6095 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
| ^~~~~~~~
/usr/include/c++/11/bits/basic_string.h:6095:5: note: template argument deduction/substitution failed:
main.cpp:40:42: note: ‘wektor’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
40 | cout << "Suma wektorow - " << w1 + ::w1 << 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/ostream:38,
from /usr/include/c++/11/iostream:39,
from main.cpp:9:
/usr/include/c++/11/bits/basic_string.tcc:1169:5: note: candidate: ‘template std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const _CharT*, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)’
1169 | operator+(const _CharT* __lhs,
| ^~~~~~~~
/usr/include/c++/11/bits/basic_string.tcc:1169:5: note: template argument deduction/substitution failed:
main.cpp:40:42: note: mismatched types ‘const _CharT*’ and ‘wektor’
40 | cout << "Suma wektorow - " << w1 + ::w1 << 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/ostream:38,
from /usr/include/c++/11/iostream:39,
from main.cpp:9:
/usr/include/c++/11/bits/basic_string.tcc:1189:5: note: candidate: ‘template std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(_CharT, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)’
1189 | operator+(_CharT __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs)
| ^~~~~~~~
/usr/include/c++/11/bits/basic_string.tcc:1189:5: note: template argument deduction/substitution failed:
main.cpp:40:42: note: ‘wektor’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
40 | cout << "Suma wektorow - " << w1 + ::w1 << endl;
| ^~
In file included from /usr/include/c++/11/string:55,
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/ostream:38,
from /usr/include/c++/11/iostream:39,
from main.cpp:9:
/usr/include/c++/11/bits/basic_string.h:6132:5: note: candidate: ‘template std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)’
6132 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
| ^~~~~~~~
/usr/include/c++/11/bits/basic_string.h:6132:5: note: template argument deduction/substitution failed:
main.cpp:40:42: note: ‘wektor’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
40 | cout << "Suma wektorow - " << w1 + ::w1 << endl;
| ^~
In file included from /usr/include/c++/11/string:55,
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/ostream:38,
from /usr/include/c++/11/iostream:39,
from main.cpp:9:
/usr/include/c++/11/bits/basic_string.h:6148:5: note: candidate: ‘template std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, _CharT)’
6148 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
| ^~~~~~~~
/usr/include/c++/11/bits/basic_string.h:6148:5: note: template argument deduction/substitution failed:
main.cpp:40:42: note: ‘wektor’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
40 | cout << "Suma wektorow - " << w1 + ::w1 << endl;
| ^~
In file included from /usr/include/c++/11/string:55,
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/ostream:38,
from /usr/include/c++/11/iostream:39,
from main.cpp:9:
/usr/include/c++/11/bits/basic_string.h:6160:5: note: candidate: ‘template std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)’
6160 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
| ^~~~~~~~
/usr/include/c++/11/bits/basic_string.h:6160:5: note: template argument deduction/substitution failed:
main.cpp:40:42: note: ‘wektor’ is not derived from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
40 | cout << "Suma wektorow - " << w1 + ::w1 << endl;
| ^~
In file included from /usr/include/c++/11/string:55,
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/ostream:38,
from /usr/include/c++/11/iostream:39,
from main.cpp:9:
/usr/include/c++/11/bits/basic_string.h:6166:5: note: candidate: ‘template std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&)’
6166 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
| ^~~~~~~~
/usr/include/c++/11/bits/basic_string.h:6166:5: note: template argument deduction/substitution failed:
main.cpp:40:42: note: ‘wektor’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
40 | cout << "Suma wektorow - " << w1 + ::w1 << endl;
| ^~
In file included from /usr/include/c++/11/string:55,
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/ostream:38,
from /usr/include/c++/11/iostream:39,
from main.cpp:9:
/usr/include/c++/11/bits/basic_string.h:6172:5: note: candidate: ‘template std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&)’
6172 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
| ^~~~~~~~
/usr/include/c++/11/bits/basic_string.h:6172:5: note: template argument deduction/substitution failed:
main.cpp:40:42: note: ‘wektor’ is not derived from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
40 | cout << "Suma wektorow - " << w1 + ::w1 << endl;
| ^~
In file included from /usr/include/c++/11/string:55,
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/ostream:38,
from /usr/include/c++/11/iostream:39,
from main.cpp:9:
/usr/include/c++/11/bits/basic_string.h:6194:5: note: candidate: ‘template std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const _CharT*, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&)’
6194 | operator+(const _CharT* __lhs,
| ^~~~~~~~
/usr/include/c++/11/bits/basic_string.h:6194:5: note: template argument deduction/substitution failed:
main.cpp:40:42: note: mismatched types ‘const _CharT*’ and ‘wektor’
40 | cout << "Suma wektorow - " << w1 + ::w1 << endl;
| ^~
In file included from /usr/include/c++/11/string:55,
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/ostream:38,
from /usr/include/c++/11/iostream:39,
from main.cpp:9:
/usr/include/c++/11/bits/basic_string.h:6200:5: note: candidate: ‘template std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(_CharT, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&)’
6200 | operator+(_CharT __lhs,
| ^~~~~~~~
/usr/include/c++/11/bits/basic_string.h:6200:5: note: template argument deduction/substitution failed:
main.cpp:40:42: note: ‘wektor’ is not derived from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
40 | cout << "Suma wektorow - " << w1 + ::w1 << endl;
| ^~
In file included from /usr/include/c++/11/string:55,
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/ostream:38,
from /usr/include/c++/11/iostream:39,
from main.cpp:9:
/usr/include/c++/11/bits/basic_string.h:6206:5: note: candidate: ‘template std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, const _CharT*)’
6206 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
| ^~~~~~~~
/usr/include/c++/11/bits/basic_string.h:6206:5: note: template argument deduction/substitution failed:
main.cpp:40:42: note: ‘wektor’ is not derived from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
40 | cout << "Suma wektorow - " << w1 + ::w1 << endl;
| ^~
In file included from /usr/include/c++/11/string:55,
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/ostream:38,
from /usr/include/c++/11/iostream:39,
from main.cpp:9:
/usr/include/c++/11/bits/basic_string.h:6212:5: note: candidate: ‘template std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, _CharT)’
6212 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
| ^~~~~~~~
/usr/include/c++/11/bits/basic_string.h:6212:5: note: template argument deduction/substitution failed:
main.cpp:40:42: note: ‘wektor’ is not derived from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
40 | cout << "Suma wektorow - " << w1 + ::w1 << endl;
| ^~
main.cpp:41:11: error: no match for ‘operator*’ (operand types are ‘wektor’ and ‘wektor’)
41 | if(w1 * ::w1 == 0) cout << "Wektory są prostopadłe";
| ~~ ^ ~~~~
| | |
| wektor wektor