I'm working on a project where certain objects are referenced counted -- it's a very similar setup to COM. Anyway, our project does have smart pointers that alleviate the need to explicitly call Add() and Release() for these objects. The problem is that sometimes, developers are still calling Release() with the smart pointer.
What I'm...
I don't understand why the compiler can't resolve the correct overload to use here. (code below) There is only one version of Add() that is appropriate- BigFoo is an IFoo, and does not implement IEnumerable where T is an IFoo. But it insists on reporting an ambiguity. Any ideas? I tried adding a second generic type parameter- Add where T...
I'm having some trouble using reflection to differentiate between a non-generic and a generic method on a generic class. Here's a test case I'm working with:
public class Foo<T>
{
public string Bar( T value ) { return "Called Bar(T)"; }
public string Bar( int value ) { return "Called Bar(int)"; }
public static void CallBar<TR>(F...
I have a simple class for which I want to overload operator as below
class MyClass
{
public:
int first;
template <typename T>
T operator () () const { return first; }
};
And the somewhere else I have
MyClass obj;
int i = obj(); // This gives me an error saying could not deduce
// template argum...
I'm just wondering about an implementation detail of sScala generics. In C# one can declare a class as:
class Foo<T1>{}
class Foo<T1, T2>{}
In Scala however the same thing would have to be declared as
class Foo0[T1]{}
class Foo1[T1, T2]{}
Notice how the class name is forced to be changed for multiple generic parameters. Is there ...
I've got some code where I would like to build a vector of elements using the mapped values in a map. The code below works fine in Visual Studio (and seems legit as far as I can tell), but g++ disagrees.
template<class PAIR>
typename PAIR::second_type foo(const PAIR& arg)
{
return (arg.second);
}
class A
{
private:
typedef std...
In Python 2.6 (and earlier) the hex() and oct() built-in functions can be overloaded in a class by defining __hex__ and __oct__ special functions. However there is not a __bin__ special function for overloading the behaviour of Python 2.6's new bin() built-in function.
I want to know if there is any way of flexibly overloading bin(), an...
I need help on finding the problem using a custom c++ class to manage 3D positions. Here is the relevant code from the class
Punto operator+(Punto p){
return Punto(this->x + p.x, this->y + p.y, this->z + p.z);
}
Punto operator+(Punto *p){
return Punto(this->x + p->x, this->y + p->y, this->z + p->z);
}
Punto operator-...
I'm changing some classes of mine from an extensive use of getters and setters to a more pythonic use of properties.
But now I'm stuck because some of my previous getters or setters would call the corresponding method of the base class, and then perform something else. But how can this be accomplished with properties? How to call the pr...
i am using a stored procedure to run some queries in my database. The value is taken from a query string then passed to the stored procedure. the thing is, the user may select more than 1 option that generates 3 or more query string.
e.g. http://localhost.com/test.aspx?param=76&param2=79
i know how to take the values from the query...
This question is similar to this other one, with the difference that the data member in the base class is not wrapped by the descriptor protocol.
In other words, how can I access a member of the base class if I am overriding its name with a property in the derived class?
class Base(object):
def __init__(self):
self.foo = 5
cl...
Hello,
In Python, I would like to construct an instance of the Child's class directly from an instance of the Parent class. For example:
A = Parent(x, y, z)
B = Child(A)
This is a hack that I thought might work:
class Parent(object):
def __init__(self, x, y, z):
print "INITILIZING PARENT"
self.x = x
sel...
I'm trying to override Object::Equals in C++ .NET but I'm running into some difficulties
virtual bool IState::Equals(Object^ o) override{
if (o->GetType() == IState::typeid){
IState^ s = (IState^) o;
if (s->type == this->type &&
s->target_state == this->target_state &&
s->current_state == this->current_sta...
Is there a way to overload the event += and -= operators in C#? What I want to do is take an event listener and register it to different events. So something like this:
SomeEvent += new Event(EventMethod);
Then instead of attaching to SomeEvent, it actually attaches to different events:
DifferentEvent += (the listener above);
Anot...
Had the idea I'd seen at least one.
...
Unless you're programming parts of an OS or an embedded system are there any reasons to do so? I can imagine that for some particular classes that are created and destroyed frequently overloading memory management functions or introducing a pool of objects might lower the overhead, but doing these things globally??
Addition
I've just fo...
What is the best way of supporting optional data passed to a C# function?
I have web service function in .Net which defines 5 arguments:
[WebMethod]
public string UploadFile( string wsURL
, byte[] incomingArray
, string FileName
, string RecordTypeName
, MetaData[] metaDataArray)
The code of this ...
The title says it all...
Cheers
David
...
I've had a good read of the PHP specs on overloading, and most of the examples appear to be intended to simply allow defining of custom fields (similar to stdClass).
But what about the private fields defined in my class? How should these be retrieved/assigned? I could do a switch on possible values and act on certain values:
class A
{
...
There are a few topics similar to this, but I couldn't find one with a sufficient answer.
I would like to know what is the best practice for constructor overloading in Java. I already have my own thoughts on the subject, but I'd like to hear more advice.
I'm referring to both constructor overloading in a simple class and constructor ov...