constructor

Generics, abstract classes, constructors

I have an abstract base class class AbstractClass { Col<AbstractClass> parent public AbstractClass() { //do stuff } } I have two implementations class A : AbstractClass { Col<A> parent public A(Col<A> parent) :base(parent) { this.parent = parent; } } class B : AbstractC...

Reversed order of constructor calls by inheriting a constructor

I have a class that first needs to call the derived class constructor before it calls the base constructor. I know that by the following code the base constructor will be called first public class A { protected A () { //do something } } public class B : A { public B () : base() { //do something else }...

Using boost::bind with a constructor

I'm trying to create new objects and add them to a list of objects using boost::bind. For example. struct Stuff {int some_member;}; struct Object{ Object(int n); }; .... list<Stuff> a; list<Object> objs; .... transform(a.begin(),a.end(),back_inserter(objs), boost::bind(Object, boost::bind(&Stuff::some_member,_1) ) ); ...

Should constructors for WCF Services use faults for error handling?

I have a wcf service. The service itself (class that inherits the ServiceContract) has a constructor that sometimes throws exceptions. I want to present the user a message if the service fails. Should I use faults like I would for a service method? ...

can constructors actually return Strings?

Hi all, I have a class called ArionFileExtractor in a .java file of the same name. public class ArionFileExtractor { public String ArionFileExtractor (String fName, String startText, String endText) { String afExtract = ""; // Extract string from fName into afExtract in code I won't show here return afExtract; } Howeve...

private constructor, subclassing and sealed

If one can prevent subclassing by declaring private constructor in the base class, why do we need "sealed" keyword? Is it so because CLI can optimize it better? maybe. Thanks. ...

Naudio - 'WaveOut' does not contain a constructor that takes '3' arguments

Hi, this question derives from my previous thread Play mp3 from internet without FileOpenDialog I really hope someone knows anything about this. I was told to use a WebRequest to start a download stream and then play the stream instead of playing a locally stored file. However, trying to use the code from PlayMp3FromUrl gives me this e...

VS2008 C++ Compiler error?

this compiles :-) string name; name = 1; this does not: string name = 1; any thoughts? I know that this is wrong. . . that is not the point. The first gives a smiley face. ...

How to create a 2D array in C++ using this specific container

I'm trying to port a int a[][] from Java to C++. I'm using this class as a container ArrayRef for ints because it handles references, and the project uses it extensively. In the AbstractReader class I declared const ArrayRef<int> START_END_PATTERN_; const ArrayRef<int> MIDDLE_PATTERN_; const ArrayRef<ArrayRef<int> > L_PATTERNS_; co...

About Constructors in Java

Are constructors allowed to throw exceptions? ...

One-arg Constructor A(x) implicitly invoking super() than super(x)

class A{ A(int x){} } class B extends A{ B(int x){} public static void main(String args[]){ B b = new B(10); } } I understand this would throw an error (one-arg constructor for B, implicitly calls super(), whereby no default-arg constructor exists for A). I am curious why one-arg constructor for B, does not...

C++ privately contructed class

How can I call a function and keep my constructor private? If I make the class static, I need to declare an object name which the compiler uses to call the constructor, which it cannot if the constructor is private (also the object would be extraneous). Here is the code I am attempting to use (it is not compilable): I want to keep the ...

C++ keeping a list of objects and calling a contructor through another function

why isnt my object being created? When I do it like so, I am told error C2065: 'AllReferrals' : undeclared identifier as well as error C2228: left of '.push_back' must have class/struct/union. If I put the list initialization before the class I get error C2065: 'AllReferrals' : undeclared identifier. Thanks! #include <iostream> #inclu...

Constructor Polymorphism Help

I have a UserControl that has a BaseClass object as a public member. Right now I'm doing the following to discern between which type of object I need to instantiate: Public WithEvents theForm As OrderForm Protected Sub Page_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Me.Load Select Case Form Case...

[ASP.NET MVC] Controller constructor called on every request

I'm trying to test a very simple form that uses only a list and a create. This is the controller: public class PositionsController : Controller { private readonly IPositionRepository _positions; // default constructor public PositionsController() { _positions = new TestPositionRepository(); } // DI cons...

Adding "this" reference to Array fails in Java Constructor

I am absolute clueless why the following code keeps throwing NullpointerExceptions. I was not able to understand or debug this (its stripped down code from a larger class)... The code is based on the "Enum Pattern" and I want to keep a List/Map of all "Constants" that are contained in the class (I might be using Reflection for this but ...

Calling timeconsuming functions from a constructor

What I'm looking right now is a set of classes derived from a common base class. Most, but not all, of the classes require some input parameters which are obtained through modal dialogs. Those dialogs are set up and executed in the constructor of the classes. As long as the dialog isn't finished, the object isn't constructed completely. ...

In Java, when is the constructor for an enumerated constant invoked?

To use a contrived example in Java, here's the code: enum Commands{ Save("S"); File("F"); private String shortCut; private Commands(String shortCut){ this.shortCut = shortCut; } public String getShortCut(){ return shortCut; } } I have the following test/driver code: public static void main(String args[]){ System.ou...

Conversion constructor vs. conversion operator: precedence

Reading some questions here on SO about conversion operators and constructors got me thinking about the interaction between them, namely when there is an 'ambiguous' call. Consider the following code: class A; class B { public: B(){} B(const A&) //conversion constructor { cout << "cal...

Using friends with base classes for Boost Parameter

I'm using the Boost Parameter tutorial to create a named-parameter constructor for a playing card generator. The tutorial says to put the ArgumentPack into a base class, but I want to modify variables in the card generator class. I've thought about doing this: class CGconstructor_base { public: template<class ArgumentPack> C...