Take into account the weirdness of abstract classes in C++

Bug #1209898 reported by Richard Gomes
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
JQuantLib
New
Low
Unassigned

Bug Description

In C++ it's possible to do something like this...

public MyClass {
    virtual double someFunction() const = 0;
}
MyClass myClass();

... which could be translated to Java like this:

abstract public MyClass {
    abstract double someFunction();
}
MyClass myClass = new MyClass();

... which does not compile because MyClass is abstract and cannot be directly instantiated;

There are 2 ways to solve this problem:

1. Create code like below everytime it is necessary:

MyClass myClass = new MyClass() {
    double someFunction() {
        throw new UnsupportedOperationException();
    }
}

2. Declare a default implementation and employ it when necessary:

public DefaultClass extends MyClass {
    double someFunction() {
        throw new UnsupportedOperationException();
    }
}

MyClass myClass = new DefaultClass();

=============
Relationships
=============
child of http://bugs.launchpad.net/bugs/jquantlib-400

Tags: tools
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.