I have a C++/CLI wrapper around native .lib and .h files. I use the AutoPtr class pretty extensively in the wrapper class to manage the unmanaged objects I create for wrapping. I have hit a roadblock with the copy constructor/assignment operator.
Using the AutoPtr class from Mr. Kerr: http://weblogs.asp.net/kennykerr/archive/2007/03/2...
i have an overloaded operator << trying to make it work like this
mystream<<hex<<10;
i have overloaded method
mytream& operator<<(ios_base& (*m) ios_base&)
This gets called whenever hex is encountered cause the parameter passed in the method is a function pointer of type same as hex or like some other output manipulators like de...
I found this question on archived file at joelonsoftware.com http://discuss.joelonsoftware.com/default.asp?joel.3.594503.11
"Hi,
I'm having a particularly slow day and
can't get my head round an operator
overloading problem. I would like a
class to be able to accept data via an
insertation operator, i.e:
myClassInst...
_com_ptr_ has an overloaded operator&() with a side effect. If I have a variable:
_com_ptr_t<Interface> variable;
How could I retrieve its address (_com_ptr_t<Interface>* pointer) without calling the overloaded operator and triggering the side effect?
...
Is there a difference between defining a global operator that takes two references for a class and defining a member operator that takes only the right operand?
Global:
class X
{
public:
int value;
};
bool operator==(X& left, X& right)
{
return left.value == right.value;
};
Member:
class X
{
int value;
bool operato...
I am trying to write a piece of code for fun using C++ templates.
#include <iostream>
#include <vector>
template <class Container>
std::ostream& operator<<(std::ostream& o, const Container& container)
{
typename Container::const_iterator beg = container.begin();
o << "["; // 1
while(beg != container.end())
{
o <<...
Hi all.
I've got a class :
class base
{
public :
base & operator +=(const int value) = 0;
// base operator + (const int val) = 0; // HOW DO I DO THIS ?
};
And a child class that derives from it
class derived : public base
{
public :
derived() : m_val(0) {}
derived(const derived & val) : m_val(val.m_val) {}
base & operator = (co...
Apparently alot of ORM's do something like this:
query.filter(username == "bob")
to generate sql like
... WHERE username = 'bob'
Why override the == operator instead of something like:
query.filter(username.eq("bob"))
...
Hi Guys,
I have following class:-
class myclass
{
size_t st;
myclass(size_t pst)
{
st=pst;
}
operator int()
{
return (int)st;
}
int operator+(int intojb)
{
return int(st) + intobj;
}
};
this works fine as long as I use it like this:-
char* src="This is test string"...
I have a class that uses a struct, and I want to overload the << operator for that struct, but only within the class:
typedef struct my_struct_t {
int a;
char c;
} my_struct;
class My_Class
{
public:
My_Class();
friend ostream& operator<< (ostream& os, my_struct m);
}
I can only compile when I declare the operator<< ove...
While porting Windows code to Linux, I encountered the following error message with GCC 4.2.3. (Yes, I'm aware that it's a slight old version, but I can't easily upgrade.)
main.cpp:16: error: call of overloaded ‘list(MyClass&)’ is ambiguous
/usr/include/c++/4.2/bits/stl_list.h:495: note: candidates are: std::list<_Tp, _Alloc>::list(cons...
Hello there,
I am trying to create my own std::string wrapper to extend its functionality.
But I got a problem when declaring the << operator.
Here's my code so far:
my custom string class:
class MyCustomString : private std::string
{
public:
std::string data;
MyCustomString() { data.assign(""); }
MyCustomString(char *value) { d...
This is a totally hypothetical question, but I have to know the answer.
I assume most C++ compilers are written in assembly. Which makes them different languages entirely (I could be wrong). That being said if I were going to create a cout style function for plain old C, how would I do it? cout has some very impressive features take thi...
hello,
i have this class called MemoryManager,
it is supposed to implement a simple smart pointer, (count reference);
i have a vector where i store the requested pointers,and i return the index of the pointer to the caller..
when a user creates a pointer of type MemoryManager he calls an initializer function called modified_malloc(s...
There's a ton of information available on overloading operator<< to mimic a toString()-style method that converts a complex object to a string. I'm interested in also implementing the inverse, operator>> to deserialize a string into an object.
By inspecting the STL source, I've gathered that:
istream &operator>>(istream &, Object &);
...
Say I want a C++ function to perform arithmetic on two inputs, treating them as a given type:
pseudo:
function(var X,var Y,function OP)
{
if(something)
return OP<int>(X,Y);
else if(something else)
return OP<double>(X,Y);
else
return OP<string>(X,Y);
}
functions that fit OP might be like:
template <class T> add(var X,var Y)
...
Hi!
I have a struct for which i want to define a relative order by defining < , > , <= and >= operators. actually in my order there won't be any equality, so if one struct is not smaller than another, it's automatically larger.
I defined the first operator like this:
struct MyStruct{
...
...
bool operator < (const MyStruct &b) const ...
See edit at the end
I am trying to overload the + operator in C++ to allow me to add two complex numbers. (add the real and add the imaginary).
Here is my overloaded function:
ComplexNum operator+(ComplexNum x, ComplexNum y){
ComplexNum result;
result.real = (x.getReal() + y.getReal());
result.imag = (x.getImag() + y.getImag());
retu...
Hi,
I have a class CFoo with a private inner class CBar. I want to implement a stream ouput operator for CFoo, which in turn uses a stream output for CBar in it's implementation. I can get this working when CFoo is in the common namespace, but when i place it in a new namespace (namespace foobar), the operator can no longer access the pr...
In Sql Server 2008, they added new DATE and TIME datatypes, complimenting DATETIME.
I wanted to combine a DATE and a TIME to a DATETIME, and thought maybe the obvious would work, and I could do
SELECT DATEFLD + TIMEFLD FROM MYTABLE
and DATE + TIME would return the corresponding DATETIME. Unfortunately, that's a little too obvious, a...