473,320 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Overloaded operator

I've got a problem trying to compile a program written in Visual C++ in MinGW/GCC. While it works in VC++, MinGW dies on this piece of code:

Expand|Select|Wrap|Line Numbers
  1.         ByteBuffer &operator<<(const std::string &value)
  2.         {
  3.         append((uint8 *)value.c_str(), value.length());
  4.             append((uint8)0);
  5.             return *this;
  6.         }
with this error:
Expand|Select|Wrap|Line Numbers
  1. ./shared/ByteBuffer.h: In member function `ByteBuffer& ByteBuffer::operator<<(const std::string&)':
  2. ./shared/ByteBuffer.h:112: error: invalid use of undefined type `const struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >'
  3. C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/stringfwd.h:56: error: declaration of `const struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >'
  4. ./shared/ByteBuffer.h:112: error: invalid use of undefined type `const struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >'
  5. C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/stringfwd.h:56: error: declaration of `const struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >'
  6.  
I don't have any idea what could be wrong (I'm kinda new to this, as you may have guessed), so any help is appreciated.

Regards,

shlainn
Mar 23 '08 #1
3 2128
Laharl
849 Expert 512MB
Did you #include<string>? Also, the << and >> operators cannot be class member functions since their first input must be an istream& or ostream&, depending, rather than the invisible 'this'. They can be friend functions (and if you want to associate them with a class, should be), but they can't be member functions.
Mar 23 '08 #2
Did you #include<string>?
Actually I thought so. But when I checked it wasn't there. Stupid me,

thanks for the heads up.

Shlainn
Mar 23 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
How are you getting this to work?

operator<< requires two arguments while your function shows only one.

Plus, in order to overload an operator one of the arguments must be a user-defined type. Yours uses str::string.

Are you sure this ever compiled?
Mar 23 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Nitin Bhardwaj | last post by:
Thanx in advance for the response... I wanna enquire ( as it is asked many a times in Interviews that i face as an Engg PostGraduate ) about the overloading capability of the C++ Language. ...
5
by: Andy Jarrell | last post by:
I'm trying to inherit from a specific class that has an overloaded operator. The problem I'm getting is that certain overloaded operators don't seem to come with the inheritance. For example: ...
1
by: masood.iqbal | last post by:
I have a few questions regarding overloaded typecast operators and copy constructors that I would like an answer for. Thanks in advance. Masood (1) In some examples that I have seen...
14
by: ambar.shome | last post by:
Hi, As you know there are few operators in C++ which cant be overloaded. They are: .., .*, ::, ?: , new , delete , sizeof , typeid , static_casr , dynamic_cast , const_cast ,...
1
by: Alex Zhitlenok | last post by:
Hi, My question is how to resolve in C# ambiguous overloaded operators? Let say, I have two unrelated classes A and B, each one implements overloaded operator + with the first parameter of type...
3
by: cybertof | last post by:
Hello, Is it possible in C# to have 2 overloaded functions with - same names - same parameters - different return type values If no, is it possible in another language ?
2
by: B. Williams | last post by:
I have an assignment for school to Overload the operators << and >and I have written the code, but I have a problem with the insertion string function. I can't get it to recognize the second of...
5
by: raylopez99 | last post by:
I need an example of a managed overloaded assignment operator for a reference class, so I can equate two classes A1 and A2, say called ARefClass, in this manner: A1=A2;. For some strange reason...
9
by: rohits123 | last post by:
I have an overload delete operator as below ////////////////////////////////// void operator delete(void* mem,int head_type) { mmHead local_Head = CPRMemory::GetMemoryHead(head_type);...
2
by: subramanian100in | last post by:
overloaded operator=() -------------------------------- overloaded assignment operator should be a non-static MEMBER function of a class. This ensures that the first operand is an lvalue. If...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.