I am creating an explicit conversion operator to convert between a generic list of entity types to a generic list of model types. Does anyone know why I get the following error:
User-defined conversion must convert to or from the enclosing type
I already have an explicit conversion operator between Entity.objA and Model.objA which...
I have a class which contains a few boost::numeric::ublas::matrix's within it. I would like to overload the class's operators (+-*/=) so that I can act on the set of matrices with one statement.
However this seems to require temporary instances of my class to carry values around without modifying the original class. This makes sense...
I'm maintaining a plugin (implemented as a dll) for a big closed source application. This has been working fine for years. However, with the latest update to it's SDK the vendor overloaded global operators new and delete. This causes lots of trouble for me. What happens is that my plugin allocates a string. I pass this string into a stat...
This is in C++.
So, I'm starting from scratch writing a game engine for fun and learning from the ground up. One of the ideas I want to implement is to have game object state (a struct) be double-buffered. For instance, I can have subsystems updating the new game object data while a render thread is rendering from the old data by guar...
I have this function
public static implicit operator MyClass(string v) { return new MyClass(v); }
and write var.myclass = null;. This calls the implicit operator and passes null as string, which causes havoc in my code (i use reflection and would not like to add a special case). How can i write myclass = null without causing the impli...
Why does C# require operator overloads to be static methods rather than member functions (like C++)? (Perhaps more specifically: what was the design motivation for this decision?)
...
Hello,
I have an abstract virtual base class Foo from which I derive many other classes that differ in small ways. I have a factory that creates the derived classes and returns Foo*. One of my bigger problems is in my operator overloads, I need to make sure that the DFoo does not get operated on by DFoo1 (not shown). I have currently ha...
As per the MSDN doc on __interface, a Visual C++ interface "Cannot contain constructors, destructors, or operators."
Why can't an interface contain an operator? Is there that much of a difference between a get method that returns a reference:
SomeType& Get(WORD wIndex);
and the overloaded indexer operator?
SomeType& operator[](WORD ...
Okay so I have a class that has 'weak typing' I.E. it can store many different types defined as:
#include <string>
class myObject{
public:
bool isString;
std::string strVal;
bool isNumber;
double numVal;
bool isBoolean;
bool boolVal;
double operator= (const myObject &);
};
I would like ...
I've overloaded the global operator new/delete/new[]/delete[] but simple tests show that while my versions of new and delete are being called correctly, doing simple array allocations and deletes with new[] and delete[] causes the implementations in newaop.cpp and delete2.cpp to be called.
For example, this code
int* a = new int[10];
...
I was wondering how can you use operators along with 'this'. To put an example:
class grd : clm
{
inline int &operator()(int x, int y) { return g[x][y]; }
/* blah blah blah */
};
grd grd::crop(int cx1, int cy1, int cx2, int cy2)
{
grd ngrd(abs(cx1-cx2), abs(cy1-cy2));
int i, j;
//
for (i = cx1; i < cx2; i++)
...
I've always wondered about this for a bit, but why is operator overloading not available for classes in Delphi?
I remember reading an answer once while on the run, and it said it would come in conflict with something, but I can't remember much. As far as I can tell, only the implicit operator may cause a bit of problems since classes ar...
In many scenarios, operator overloads allow you to express yourself better. Why are they hardly used in C#?
...
I'm from a C++ background and just started Java today. Say I have a class with a couple of data members. For example:
public class Person {
//Constructors/Destructor
public Person(String strFirstName, String strLastName) {
m_strFirstName = strFirstName;
m_strLastName = strLastName;
m_strFullName = m_st...
I can't figure out why the following code doesn't compile. The syntax is the same as my other operator overloads. Is there a restriction that the << overload must be friended? If so, why? Thanks for any help.
This doesn't work -
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
class Test
{
public:
explici...
Why is the + operator for List deprecated in Scala?
http://www.scala-lang.org/docu/files/api/scala/List.html#%2B%28B%29
...
Hello!
I have the following question:
Assume base class A with method:
A& operator+(A& a) {...}
I also have a derived class B which overloads (or at least it should so) this method:
A& operator+(B& b) {...}
The problem is that if i want to call something like:
b + a (where b is of type B and a of type A) i get a compile error.
(e...
Suppose i have declared subscript operators in a class
char& operator[] (int index);
const char operator[](int index) const;
In what condition the second overload is called. Is it only called through a const object.
In the following scenarios which version of operator will be called.
const char res1 = nonConstObject[10];
nonCons...
Hello,
I'm implementing vector class and I need to get an opposite of some vector. Is it possible to define this method using operator overloading?
Here's what I mean:
Vector2f vector1 = -vector2;
Here's what I want this operator to accomplish:
Vector2f& oppositeVector(const Vector2f &_vector)
{
x = -_vector.getX();
y = -_vector....
I've this program
#include <iostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
using namespace std ;
#if 0
namespace skg
{
template <class T>
struct Triplet ;
}
template <class T>
ostream& operator<< (ostream& os, const skg::Triplet<T>& p_t) ;
#endif
namespace skg
{
template <class T>
struc...