operator-overloading

ADT - Iterators - operator ++

This isnt a homework question. I took data structures at a Community College and now that i am at the university i talked to the teacher about there data structures class. Now, since its really different and the class i took transferred, He gave me one of there assignments and said play with it. We never did any containers, wrappers,temp...

Why is "operator void" not invoked with cast syntax?

While playing with this answer by user GMan I crafted the following snippet (compiled with Visual C++ 9): class Class { public: operator void() {} }; Class object; static_cast<void>( object ); (void)object; object.operator void(); after stepping over with the debugger I found out that casting to void doesn't invoke Class:...

Question about the ostream operator <<.

Hi all. Let's say I make a class, like, which contains a char array. Now, what operator handles this: myClass inst; cout << inst; At the "cout << inst;" what is called, by simply the class' name? Thanks. ...

friend declaration declares a non-template function

I have a base Class akin to the code below. I'm attempting to overload << to use with cout. However, g++ is saying: base.h:24: warning: friend declaration ‘std::ostream& operator<<(std::ostream&, Base<T>*)’ declares a non-template function base.h:24: warning: (if this is not what you intended, make sure the function template has alread...

Some compiler errors concerning an overloaded operator on a template in c++

Hi all, I have some code with a few errorr I do not understand how to fix at all. I have asked my professor and TA, and consulted the internet with no luck, apart from understanding more precisely what the errors mean. From what I can tell, the compiler is either confusing my overloaded operator with built in operators, or it is not re...

C++ - overloading assignment operator for default types

Hi, I want to overload the assignment operator for types like "int", "long" etc. That is, I want to use code like: class CX { private: int data; ... }; CX obj; int k; k = obj; // k should get the value of obj.data Apparently assignment operators cannot be friend functions. How do I achieve the above? I maybe missing something ...

How to output unsigned/signed char or <cstdint> types as integers with << in C++

Background: I have template stream operators (e.g. operator << (ostream &, std::vector <T>)) (that output container elements that may possibly be of some 8-bit integer type, (e.g. unsigned char, int_least8_t, et cetera). Problem: Default is that these types are output as char (ASCII). I only used char (or wchar_t or whatever) for ASCI...

Using overloaded operators on pointers

Hi, I overloaded the << operator of a class. How do I have to overload the operator if I want to use it on pointers, like the following? class A { std::string operator<<(std::string&); } aInst << "This works"; aPointer << "This doesnt work"; aPointer->operator<<("Whereas this works but is useless"); I hope you can help me. hein...

Error CS0563 (One of the parameters of a binary operator must be the containing type)

My source code (below) is generating Error CS0563 because both of the parameters in my CombinedJobs operator+ (see "//Step 5: ..." in source code) are listed as Job (as opposed to int, double, etc). How can I change this code to eliminate this error? This code is in response to the assignment listed below. Assignment: "Design a Job cla...

Odd output from a redefined << operator in c++

Hi all, I am having a runtime error that I can not for the life of me figure out. My program almost does what I want it to, but there are some corrupted characters that print out as gibberish. The program is supposed to take in a text file that represents a forest of trees, build the forest of trees, then traverse the forest to print i...