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: - ByteBuffer &operator<<(const std::string &value)
-
{
-
append((uint8 *)value.c_str(), value.length());
-
append((uint8)0);
-
return *this;
-
}
with this error: -
./shared/ByteBuffer.h: In member function `ByteBuffer& ByteBuffer::operator<<(const std::string&)':
-
./shared/ByteBuffer.h:112: error: invalid use of undefined type `const struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >'
-
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> >'
-
./shared/ByteBuffer.h:112: error: invalid use of undefined type `const struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >'
-
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> >'
-
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
3 2128
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.
Did you #include<string>?
Actually I thought so. But when I checked it wasn't there. Stupid me,
thanks for the heads up.
Shlainn
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?
Sign in to post your reply or Sign up for a free account.
Similar topics
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.
...
|
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:
...
|
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...
|
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 ,...
|
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...
|
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 ?
|
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...
|
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...
|
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);...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
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....
|
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...
| |