Let's say I have class that acts as a "smart pointer" and releases some kind of system resource when destroyed.
class Resource{
protected:
ResourceHandle h;
public:
Resource(ResourceHandle handle)
:h(handle){
}
~Resource(){
if (h)
releaseResourceHandle(h);//external function, probably from...
Please refer to the Java code below:
class Base{
Base(){
System.out.println("Base Constructor");
method();
}
void method(){}
}
class Derived extends Base{
int var = 2;
Derived(){
System.out.println("Derived Constructor");
}
@Override
void method(){
System.ou...
Couple of questions on scala abstract types.
Do I have to use parameterized [] types if I want to use the type in a constructor value? ie. is it possible to have a class with abstract constructor parameter types? If I get rid of [T1,T2] and use INode#TKey and INode#TValue as the constructor parameter types, what am I doing? I get confu...
I decided it would be a fun side project to do some work on tsocks, since it hasn't seen any updates in 8 years. It's hosted here on GitHub.
I only made cosmetic changes to the code so far, but now I've run into a compiler error. According to dlopen(3):
The obsolete symbols _init() and _fini()
[...]
Using these routines [...] is not r...
I was looking at the Google C++ Style Guide and they have decided not to use exceptions in C++ code, relying on return values instead.
My question is: How do you handle failure in constructors in this case, since you cannot return a value in those.
Thanks!
...
public class User
{
private final String _first_name;
private final String _last_name;
private final String _org_ID;
private final TimeZone _time_zone;
private final InternetAddress _email;
private final Date _last_login;
private final Date _creation_date;
public User( final String org_I...
Hi all,
I want to see the values of the created string objects in the system. To do so, I override the String.class by using Xbootclasspath option. In my new overriding class I modified constructors of String.class by adding the line System.out.println(value) to each, such that
public String() {
this.offset = 0;
this.count = 0;
this...
What does this code do? Why is there two sets of constructor parameters?
class A(val x: Int)(val y: Int)
I can initialize an object and use both fields:
val a = new A(5)(7)
println(a.x + ", " + a.y)
If I make it a case class, I can match only by the first set of parameters.
case class A(x: Int)(y: Int)
val a = A(5)(7)
a match {
...
I found an error in my scala code, which puzzles me. Below is a simplified version of the problem.
In the constructor of an abstract class, I want to check a few asserts about the abstract methods.
Thus when an object of a subclass is made, these asserts are checked, to see if all is implemented as it should.
It goes wrong when the sub...
In C#/.NET:
I have 2 concrete classes. Class A and B. Class B subclasses from Class A.
How many instances (objects on the heap) and references from the stack to the heap objects are created for each line of code:
ClassB b = new ClassB();
ClassA a = new ClassB();
Thanks!
...
I heard that const members must be explicitly intialized, but the following compiles for me:
class someClass
{
int const x;
};
int main()
{
return 0;
}
...
how to get a class constructor function name without instantiating the class?
example:
$class = 'someClass';
$constructor = somehow get constructor;
$args = array();
$object = call_user_func_array(array($class,$constructor),$args);
what I need is to create a object by passing a undetermined number of variables into it's constructor....
What is the difference between this:
public class Foo {
private Bar bar;
public Foo() { bar = new Bar(); }
}
and this:
public class Foo {
private Bar bar = new Bar();
public Foo() { }
}
...
VB6 class modules have no parameterized constructors. What solution have you chosen for this? Using facory methods seems like the obvious choice, but surprise me!
...
Why cannot initialize my array of strings in my constructor? I get the following error:
internal compiler error: Segmentation fault|
at these two lines in the constructor:
suits = {"Clubs", "Diamonds", "Hearts", "Spades"};
denominations = {"Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"};
class Card
{
publ...
I'm having some trouble using multiple constructors in java.
what I want to do is something like this:
public class MyClass {
// first constructor
public MyClass(arg1, arg2, arg3) {
// do some construction
}
// second constructor
public MyClass(arg1) {
// do some stuff to calculate arg2 and arg3
this(arg1, arg2, ar...
I want to have a static method in a parent class that creates instances of whatever subclass i call this method on.
An example to make this more clear:
class parent {
public static method make_objects($conditions){
for (...){
// here i want to create an instance
// of whatever subclass i am calling ...
Normally, if I want to pass arguments from $myarray to $somefunction I can do this in php using
call_user_func_array($somefunction, $myarray);
However this does not work when the function one wishes to call is the constructor for an object. For fairly obvious reasons it does not work to do:
$myobj = new call_user_func_array($classna...
I tried to use copy constructor using statement:
X y = X();
But copy constructor is not being called. I am using g++ 4.1.0. I set both X(const X&) and X(x&) constructor in the class.
Is this supposed to work or I am doing some very basic problem in the code?
My code for the class is
class A
{
public:
int i;
A(int ii)
{
...
Given a class such as:
type MyClass() =
member this.Greet(x) = printfn "Hello %s" x
is it appropriate to initialize instances using
let x = new MyClass()
or without the new?
Also, when is the use of a new constructor more useful than a do binding with parameters supplied to the type definition?
...