F
Fozya
Hi,
I have problems compiling some code that perfectly runs in VS.Net in
the G++. Here is what I got:
MyClass a;
MyClass b;
//assign values to a and b
.......
//print the sum of those objects
cout << "the sum is " << (a + b) << endl;
It work WS.Net fine but in G++ i have to write like this:
MyClass temp;
temp = a + b;
cout << "the sum is " << temp << endl;
The overloaded + operator has this signature and returns a copy of new
object.
MyClass operator +( const MyClass &a);
Thanks, in advance!
P.S. These are the error messages that I get
distance.cpp:218:2: warning: no newline at end of file
In file included from dist_test.cpp:3:
distance.h:72:7: warning: no newline at end of file
dist_test.cpp: In function `int main()':
dist_test.cpp:65: no match for `std::basic_ostream<char,
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(std::basic_ostream<_CharT,
_Traits>&(*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT =
char,
_Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:77:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(std::basic_ios<_CharT,
_Traits>&(*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT =
char, _Traits
= std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:99:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(std::ios_base&(*)(std::ios_base&)) [with
_CharT = char,
_Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:171:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(long int) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:208:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(long unsigned int) [with _CharT = char,
_Traits =
std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:146:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(bool) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/3.2.2/ostream:104:
std::basic_ostream<_CharT,
_Traits>& std::basic_ostream<_CharT, _Traits>:perator<<(short
int) [with
_CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/ostream:115:
std::basic_ostream<_CharT,
_Traits>& std::basic_ostream<_CharT, _Traits>:perator<<(short
unsigned
int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/ostream:119:
std::basic_ostream<_CharT,
_Traits>& std::basic_ostream<_CharT, _Traits>:perator<<(int)
[with _CharT
= char, _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/ostream:130:
std::basic_ostream<_CharT,
_Traits>& std::basic_ostream<_CharT, _Traits>:perator<<(unsigned
int)
[with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:234:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(long long int) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:272:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(long long unsigned int) [with _CharT = char,
_Traits =
std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:298:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(double) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/3.2.2/ostream:145:
std::basic_ostream<_CharT,
_Traits>& std::basic_ostream<_CharT, _Traits>:perator<<(float)
[with
_CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:323:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(long double) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:348:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(const void*) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:120:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(std::basic_streambuf<_CharT, _Traits>*) [with
_CharT =
char, _Traits = std::char_traits<char>]
distance.h:69: std:stream& operator<<(std:stream&,
Distance&)
/usr/include/c++/3.2.2/ostream:251:
std::basic_ostream<char,
_Traits>& std:perator<<(std::basic_ostream<char, _Traits>&, const
unsigned
char*) [with _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/ostream:246:
std::basic_ostream<char,
_Traits>& std:perator<<(std::basic_ostream<char, _Traits>&, const
signed
char*) [with _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:622:
std::basic_ostream<char, _Traits>&
std:perator<<(std::basic_ostream<char,
_Traits>&, const char*) [with _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:572:
std::basic_ostream<_CharT, _Traits>&
std:perator<<(std::basic_ostream<_CharT, _Traits>&, const char*)
[with
_CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/ostream:227:
std::basic_ostream<char,
_Traits>& std:perator<<(std::basic_ostream<char, _Traits>&,
unsigned char)
[with _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/ostream:222:
std::basic_ostream<char,
_Traits>& std:perator<<(std::basic_ostream<char, _Traits>&,
signed char)
[with _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:500:
std::basic_ostream<char, _Traits>&
std:perator<<(std::basic_ostream<char,
_Traits>&, char) [with _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/ostream:211:
std::basic_ostream<_CharT,
_Traits>& std:perator<<(std::basic_ostream<_CharT, _Traits>&,
char) [with
_CharT = char, _Traits = std::char_traits<char>]
dist_test.cpp:111:15: warning: no newline at end of file
I have problems compiling some code that perfectly runs in VS.Net in
the G++. Here is what I got:
MyClass a;
MyClass b;
//assign values to a and b
.......
//print the sum of those objects
cout << "the sum is " << (a + b) << endl;
It work WS.Net fine but in G++ i have to write like this:
MyClass temp;
temp = a + b;
cout << "the sum is " << temp << endl;
The overloaded + operator has this signature and returns a copy of new
object.
MyClass operator +( const MyClass &a);
Thanks, in advance!
P.S. These are the error messages that I get
distance.cpp:218:2: warning: no newline at end of file
In file included from dist_test.cpp:3:
distance.h:72:7: warning: no newline at end of file
dist_test.cpp: In function `int main()':
dist_test.cpp:65: no match for `std::basic_ostream<char,
/usr/include/c++/3.2.2/bits/ostream.tcc:55: candidates are:std::char_traits said:& << Distance' operator
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(std::basic_ostream<_CharT,
_Traits>&(*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT =
char,
_Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:77:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(std::basic_ios<_CharT,
_Traits>&(*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT =
char, _Traits
= std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:99:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(std::ios_base&(*)(std::ios_base&)) [with
_CharT = char,
_Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:171:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(long int) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:208:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(long unsigned int) [with _CharT = char,
_Traits =
std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:146:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(bool) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/3.2.2/ostream:104:
std::basic_ostream<_CharT,
_Traits>& std::basic_ostream<_CharT, _Traits>:perator<<(short
int) [with
_CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/ostream:115:
std::basic_ostream<_CharT,
_Traits>& std::basic_ostream<_CharT, _Traits>:perator<<(short
unsigned
int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/ostream:119:
std::basic_ostream<_CharT,
_Traits>& std::basic_ostream<_CharT, _Traits>:perator<<(int)
[with _CharT
= char, _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/ostream:130:
std::basic_ostream<_CharT,
_Traits>& std::basic_ostream<_CharT, _Traits>:perator<<(unsigned
int)
[with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:234:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(long long int) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:272:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(long long unsigned int) [with _CharT = char,
_Traits =
std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:298:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(double) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/3.2.2/ostream:145:
std::basic_ostream<_CharT,
_Traits>& std::basic_ostream<_CharT, _Traits>:perator<<(float)
[with
_CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:323:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(long double) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:348:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(const void*) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:120:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>:perator<<(std::basic_streambuf<_CharT, _Traits>*) [with
_CharT =
char, _Traits = std::char_traits<char>]
distance.h:69: std:stream& operator<<(std:stream&,
Distance&)
/usr/include/c++/3.2.2/ostream:251:
std::basic_ostream<char,
_Traits>& std:perator<<(std::basic_ostream<char, _Traits>&, const
unsigned
char*) [with _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/ostream:246:
std::basic_ostream<char,
_Traits>& std:perator<<(std::basic_ostream<char, _Traits>&, const
signed
char*) [with _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:622:
std::basic_ostream<char, _Traits>&
std:perator<<(std::basic_ostream<char,
_Traits>&, const char*) [with _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:572:
std::basic_ostream<_CharT, _Traits>&
std:perator<<(std::basic_ostream<_CharT, _Traits>&, const char*)
[with
_CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/ostream:227:
std::basic_ostream<char,
_Traits>& std:perator<<(std::basic_ostream<char, _Traits>&,
unsigned char)
[with _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/ostream:222:
std::basic_ostream<char,
_Traits>& std:perator<<(std::basic_ostream<char, _Traits>&,
signed char)
[with _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/bits/ostream.tcc:500:
std::basic_ostream<char, _Traits>&
std:perator<<(std::basic_ostream<char,
_Traits>&, char) [with _Traits = std::char_traits<char>]
/usr/include/c++/3.2.2/ostream:211:
std::basic_ostream<_CharT,
_Traits>& std:perator<<(std::basic_ostream<_CharT, _Traits>&,
char) [with
_CharT = char, _Traits = std::char_traits<char>]
dist_test.cpp:111:15: warning: no newline at end of file