EDIT:
From the answers given, it's been made rather clear to me how the design I'm asking about below should actually be implemented. With those suggestions in mind (and in response to a comment politely pointing out that my example code does not even compile), I've edited the following code to reflect what the general consensus seems t...
Given the following two interfaces (these are small examples, not my actual implementation):
public interface IAssertion<T> {
IAssertion<T> IsNotNull();
IAssertion<T> Evaluate(Predicate<T> predicate)
}
public interface IStringAssertion : IAssertion<string> {
IStringAssertion IsNotNullOrEmpty();
}
and a static factory t...
I need to know how to get something to work. I've got a class with a constructor and some constants initialized in the initializer list. What I want is to be able to create a different constructor that takes some extra params but still use the initializer list. Like so:
class TestClass
{
const int cVal;
int newX;
TestClass(i...
I saw some code that called methods on scalars (numbers), something like:
print 42->is_odd
What do you have to overload so that you can achieve this sort of "functionality" in your code?
...
A class has overloaded operators new and delete. new is public, delete is private.
When constructing an instance of this class, I get the following error:
pFoo = new Foo(bar)
example.cpp(1): error C2248: 'Foo:operator delete': cannot access private member declared in class 'Foo'
But there's no call to delete here, so what is going o...
In the following code:
public abstract class MyClass
{
public abstract bool MyMethod(
Database database,
AssetDetails asset,
ref string errorMessage);
}
public sealed class MySubClass : MyClass
{
public override bool MyMethod(
Database database,
AssetDetails asset,
ref string errorMe...
I've come across an oddity of the JLS, or a JavaC bug (not sure which). Please read the following and provide an explanation, citing JLS passage or Sun Bug ID, as appropriate.
Suppose I have a contrived project with code in three "modules" -
API - defines the framework API - think Servlet API
Impl - defines the API implementation - t...
Is there any way to override a non-virtual method? or something that gives similar results (other than creating a new method to call the desired method)?
I would like to override a method from Microsoft.Xna.Framework.Graphics.GraphicsDevice with unit testing in mind.
...
Hi!
I try to follow this article:
http://flipcode.com/archives/How%5FTo%5FFind%5FMemory%5FLeaks.shtml
to overload my new and delete functions in order to track memory leaks.
however - if i try to compile, I get a
C2365: "operator new": redefinition; previous definition was a "function"
in the file xdebug
xdebug gets included in xlo...
How can I find a generic overloaded method? For example, Queryable's
public static IQueryable<TResult> Select<TSource , TResult> ( this IQueryable<TSource> source , Expression<Func<TSource , int , TResult>> selector );
I've looked for existing solutions, and they're either not generic enough (are based on the method's parameters count...
Hi i want to do the following. I simply want to overload the [] method in order to access the instance variables... I know, it doesn't make great sense at all, but i want to do this for some strange reason :P
It will be something like this...
class Wata
attr_accessor :nombre, :edad
def initialize(n,e)
@nombre = n
@...
Hi everyone,
I have two methods that are overloads of each other
public class Car
{
public int GetPrice(string vinNumber)
{
string make = Database.GetMake(vinNumber); // expensive operation
string model = Database.GetModel(vinNumber); // expensive operation
int year = Database.GetYear(vinNumber); // expensiv...
can i overload or override methods just by using different return value ? is virtual matter in thie case ?
for example :
class A{
virtual int Foo(); // is this scenario possible with/without the keyword virtual
}
class B : public A {
virtual double Foo();
}
A* Base = new B();
int i = Base->Foo(); // will this just convert doubl...
Possible Duplicates:
Python: defining my own operators?
Rules of thumb for when to use operator overloading in python
hi.. can i overload operators in python?
if so, can i define new operators like << or ++?
thanks in advance..
...
I have a class defined in one DLL, with a certain member that is overloaded.
A second DLL imports that class, inherits from it and exports the inherited class. The inherited class overrides one of the overloads of the above member, and so looses all the other overloads.
The solution for this problem generally, AFAIK, is to use a using s...
void outputString(const string &ss) {
cout << "outputString(const string& ) " + ss << endl;
}
void outputString(const string ss) {
cout << "outputString(const string ) " + ss << endl;
}
int main(void) {
//! outputString("ambigiousmethod");
const string constStr = "ambigiousmethod2";
//! outputString(constStr);
} //...
How do I set a public variable. Is this correct?:
class Testclass
{
public $testvar = "default value";
function dosomething()
{
echo $this->testvar;
}
}
$Testclass = new Testclass();
$Testclass->testvar = "another value";
$Testclass->dosomething();
...
Hi,
I just got a seg fault in overloading the assignment operator for a class FeatureRandomCounts, which has _rects as its pointer member pointing to an array of FeatureCount and size rhs._dim, and whose other date members are non-pointers:
FeatureRandomCounts & FeatureRandomCounts::operator=(const FeatureRandomCounts &rhs)
{
i...
Edit: C# 3.0, net 3.5.
I am C++ programmer, so maybe I miss some simple solution in C#.
Simplified example:
I have several classes inherited from class MyBase (with method Inc). The inherited classes may override Inc. I have several overloaded "functions" (static methods) for the inherited classes:
void Print(MyInherited1 i1) ....
voi...
I have defined two classes below.
public class junk {
private BigInteger a = BigIngeger.valueOf(1), b=BigInteger.valueOf(2), c;
public void DoSomething(){
c = a.add(b);
}
// ... other stuff here
}
public class junkChild extends junk{
private BigDecimal a = BigDecimal.valueOf(1), b=BigDecimal.valueOf(2), c;...