constructor

Should functions be declared with a minimal scope?

In my experience, most JS functions, constructor functions, or module-pattern functions, are declared as globals or are bound to a global namespace object. In any case, these identifiers are globally accessible. From any line of code in your system you can have: mod1 = somepackage.SomeModule(); // couple to me! Here's a quick JS exa...

Is this variation within the constructor permitted?

I want to have an overloaded constructor where I change the value of the base class depending if the "isFirstPost" is set. If it's a first post, I want the rowkey = 000000. If it's not a first post, then make it a number. Don't really think of this as an Azure problem... but I'm more interested in the C# language and making a conditio...

Clojure: creating new instance from String class name

In Clojure, given a class name as a string, I need to create a new instance of the class. In other words, how would I implement new-instance-from-class-name in (def my-class-name "org.myorg.pkg.Foo") ; calls constructor of org.myorg.pkg.Foo with arguments 1, 2 and 3 (new-instance-from-class-name my-class-name 1 2 3) I am looking fo...

How could we create "instances" of a type or record on the fly

This question is closely related to this one but i think is more general. Recently i try to create type "instances" on the fly with multimethods (or with a unique function constructor if possible), based in a metadata tag. I linked a type (a java class under the hood) with this tag and then i didnt know how to continue in a elegant way ...

how should to implement correctly a constructor of a class with stls inside

hey I i am writing a Program in C++ and for some reason the compiler finds errors , and cant find my constructor: here is my class: (inside a h file) class Adjutancy { private: vector<Vehicale*,CompareCatId>* m_vehicalesVector; map<const string,Base*>* m_baseMap; map<const int,City*>* m_citiesMap; vector<vector<Distance*>>* m_distan...

OOP Constructor question C++

Let's say that I have two classes A and B. class A { private: int value; public: A(int v) { value = v; } }; class B { private: A value; public: B() { // Here's my problem } } I guess it's something basic but I don't know how to ca...

Will the destructor of the base class called if an object throws an exception in the constructor?

Will the destructor of the base class be called if an object throws an exception in the constructor? ...

What is an in-place constructor in C++?

Possible Duplicate: C++'s placement new What is an in-place constructor in C++? e.g. Datatype *x = new(y) Datatype(); ...

How do I get the address of a certain variable in gdb

How do I get the address of a certain variable in gdb, with the command line that is. Edit : It doesn't work in constructor. ...

c++ constructors

suppose that MyClass has methods with the following prototypes: void method1(MyClass & object1);  MyClass * method 7();  What will be this method destructor, constructor, copy constructor, overloaded= or default constructor? This is one of question in my homework. I think the first one is default constructor and second one is copy...

Scala class members and constructor parameters name clash

Hi. Consider the following class written in Java: class NonNegativeDouble { private final double value; public NonNegativeDouble(double value) { this.value = Math.abs(value); } public double getValue() { return value; } } It defines a final field called value that is initialized in the constructor, by taking i...

Javascript object literal: value initialization?

Hi, i was using object literal to create an object with methods. Here a simple example. var SizeManager = { width : 800, height : 600, ratio : this.width / this.height, resize : function (newWidth) { width = newWidth; height = newWidth / ratio; } } My issue is that SizeManager.ratio returns "NaN". ...

Parameterized Factory & product classes that cannot be instantiated without the Factory

I'm working on implementing a Factory class along the lines of what is proposed in this response to a previous question: http://stackoverflow.com/questions/410823/factory-method-implementation-c/534396#534396 It's a Factory that stores a map from strings to object creation functions so I can request different types of objects from the ...

Why should the String constructor be protected instead of private here?

I'm a bit stuck on this SCJP practice question, specifically line 5 (with the String constructor). I thought it should be private, but the solution is 'protected'. I think protected access would not satisfy the requirement that all Alpha instances have the String alpha set to A. If the constructor is protected, then any other class that'...

Constructor calling a destructor

Is it possible to have a constructor calling a destructor in C#? ...

How can I get a compilation error on accidental construction?

Given 2 classes: ... class Grades{ public: Grades(int numExams) : _numExams(numExams){ _grdArr = new double[numExams]; } double GetAverage() const; ... private: // The only data members of the class int _numExams; double *_grdArr; }; class Student{ public: Student(Grades g) : _g(g){ } ......

Why use an initialization method instead of a constructor?

I just got into a new company and much of the code base uses initialization methods instead of constructors. struct MyFancyClass : theUberClass { MyFancyClass(); ~MyFancyClass(); resultType initMyFancyClass(fancyArgument arg1, classyArgument arg2, redundantArgument arg3=TODO); // several ...

Constructor SignalStrength() is not visible? What to do?

Yesterday i tried to create an object for this class to be able to use its methods getGsmBitErrorRate() and getGsmSignalStrength(), but Eclipse IDE throws me error that constructor is not visible. The line: SignalStrength x = new SignalStrength(); Target SDK set in manifest file is 7. Any ideas what can be done to solve this problem? ...

C++ Constructor error - Expected ')' before token '<'

What is wrong wit the following constructor declaration? I keep getting this error: Expected ')' before token '<' class Environment{ public: Environment(vector<vector<char> > roomData); private: //.... }; Note: ok I see what's wrong. I did not add: using namespace std; ...

c++ initialize array in constructor without using default constructor or assinment

Consider: struct A { A (int); A (const A &); }; struct B { A foo [2]; B (const A & x, const A & y) : foo {x, y} /* HERE IS THE PROBLEM */ {} }; I was expecting this to work since I'm using C++0x support in GCC4.3, which allegedly supports initialiser lists. No joy. I have a class A which has no default constructor. This is...