constructor

Getting an error about an undefined method(constructor) when I'm looking right at it? (Java)

I'm getting an error here that says I haven't defined a method, but it is right in the code. class SubClass<E> extends ExampleClass<E>{ Comparator<? super E> c; E x0; SubClass (Comparator<? super E> b, E y){ this.c = b; this.x0 = y; } ExampleClass<E> addMethod(E x){ if(c.c...

Java: If object of same parameters exists do not add new object

Here is my object constructor static class Edge { int source; // source node int destination; // destination node int weight; // weight of the edge int predecessor; // previous node public Edge() {}; public Edge(int s, int d, int w) { source = s; destination = d; weight = w; } } Now, here is the statement where...

Automatically setting class member variables in Python

Say, I have the following class in Python class Foo(object): a = None b = None c = None def __init__(self, a = None, b = None, c = None): self.a = a self.b = b self.c = c Is there any way to simplify this process? Whenever I add a new member to class Foo, I'm forced to modify the constructor. ...

Trouble understanding whence a copy constructor came

Hello everyone :) I have the following small code: template <typename T> class V { public: T x; explicit V(T & _x) :x(_x){} }; int main() { V<float> b(1.0f); // fails return 0; } And it happens to fail. The message returned by g++ 4.4.5 is: g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d...

Rewriting the JS String Constructor: Am I Way Off?

I'm on my way through Object Oriented Javascript, and I can't help but feel I've missed the boat on a given exercise. So what I'm looking for here is pointers on how I can improve my code or understanding of Constructors. Here was the challenge: Imagine the String() constructor didn't exist. Create a constructor function MyString...

Ctor Initializer: self initialization causes crash?

I had a hard time debugging a crash on production. Just wanted to confirm with folks here about the semantics. We have a class like ... class Test { public: Test() { // members initialized ... m_str = m_str; } ~Test() {} private: // other members ... std::string m_str; }; Someone changed the initialization to use c...

Delphi: Overridden virtual constructor descendant not being called by overload

Yet another in my series of questions regarding constructors in Delphi. i have a base class that has has the virtual constructor: TComputer = class(TObject) public constructor Create(Teapot: Integer); virtual; end; The constructor is virtual for the times that someone needs to call var computerClass: class of TComputer; co...

Understanding constructor visibility

Here's two simple classes, initially both have no keywords (virtual, overload, override, reintroduce): TComputer = class(TObject) public constructor Create(Teapot: Integer); end; TCellPhone = class(TComputer) public constructor Create(Teapot: Integer; Handle: string); end; i will represent these above defintions as the slightly...

Why const for implicit conversion?

After extensive reading of ISO/IEC 14882, Programming language – C++ I'm still unsure why const is needed for implicit conversion to a user-defined type with a single argument constructor like the following #include <iostream> class X { public: X( int value ) { printf("constructor initialized with %i",value); } } void impl...

What is the code : base()

What is the purpose of base() in the following code? class mytextbox : TextBox { public mytextbox() : base() { this.Text = "stack"; } } ...

What is a non-trivial constructor in C++?

I was reading this http://en.wikipedia.org/wiki/C%2B%2B0x#Modification_to_the_definition_of_plain_old_data It mentions trivial default constructor, trivial copy constructor, copy assignment operator, trivial destructor. What is trivial and not trivial? ...

Can't I define defaults if I define multiple overloaded constructors in Scala?

I've defined multiple constructors, with some default argument values in all of them. Looks correct (I can't see any ambiguity), but Scala (2.8) compiler complains: multiple overloaded alternatives of constructor define default arguments Does it mean that I can't define default values for overloaded constructors at all? Let me ill...

Malloc in C++ constructor

I have to interface with some C code from C++ class constructor (Intel library) class A{ A{ x = ippiMalloc(); if(x==NULL) ... } } In the constructor malloc function (intel version) is used. If ippiMalloc function do not succeed what is the correct way to handle it. Throw exception? ...

How to resolve 'Implicit super constructor classA() is not visible. Must explicitly invoke another constructor' ?

I am having a class 'ClassA' which is having private constructor. public final class ClassA{ private ClassA{ } public static void main(String[] arg) }{ ; ; ; } } Now, i am extending the class 'ClassA' [ final keyword is removed before doing this ] public class ClassB extends ClassA{ public static void main(Strin...

How can I initialize a const variable of a base class in a derived class' constructor in C++?

I have an abstract C++ class with no constructor. It's supposed to be a base class so other classes can inherit from it. What I am trying to do is to declare a constant variable in the base class and initialize it in each derived class' constructor but nowhere else in each one of those classes. Is it legal in C++? If so, how can I do tha...

What (not) to do in a constructor

I want to ask you for your best practices regarding constructors in C++. I am not quite sure what I should do in a constructor and what not. Should I only use it for attribute initializations, calling parent constructors etc.? Or might I even put more complex functions into them like reading and parsing configuration data, setting up ex...

IPhone - copyWithZone leak

Testing my app on the device it returns a leak whe i call the copy of a custom object ande i can't understand why. this is the call: NSMutableArray *arr = [[NSMutableArray alloc] initWithCapacity:5]; for (SinglePart *sp in [copyFrom partList]) { [arr addObject:[sp copy]]; } self.partList = arr; [arr release]; this is the method:...

Can I override a constructor using metaprogramming limited to a scope in groovy?

I'd like to override the constructor of a class for testing. I can do it like this: SomeClass.metaClass.constructor = { Map params -> def instance = BeanUtils.instantiateClass(SomeClass) instance.apply(params) instance } That works, but I need the new constructor to apply to only some instances. In particular, I'd ...

Why do I get an ambiguous error when calling a Constructor inside of the same class in Java?

I can't figure out why i'm getting an ambiguous error. This is a sample code of what I have: public class MyString{ //Data: private char[] theString; //constructors: public MyString(){ // default constructor } public MyString(String s){ // parameterized constructor } public MyString(char[] s){ // paramete...

Java - Leaking this in constructor

I'd like to avoid (most of the) warnings of Netbeans 6.9.1, and I have a problem with the 'Leaking this in constructor' warning. I understand the problem, calling a method in the constructor and passing "this" is dangerous, since "this" may not have been fully initialized. It was easy to fix the warning in my singleton classes, because...