constructor-overloading

Python: Problem with overloaded constructors

WARNING: I have been learning Python for all of 10 minutes so apologies for any stupid questions! I have written the following code, however I get the following exception: Message File Name Line Position Traceback Node 31 exceptions.TypeError: this constructor takes no arguments class Computer: n...

Overload "base" contructor or "this" contructor?

I have few types that derive from simplified Base as shown below. I am not sure whether to use base class's constructor or this constructor when overloading constructors. ConcreteA overloads constructors purely using base constructors, while ConcreteB overloads using this for the first two overloads. What would be a better way of ove...

Optional reference member - is it possible?

I have the following class class CItem { public: CItem(CRegistry &Registry) _Registry(Registry) {Registry.Register();} ~CItem() {_Registry.Unregister()}; private: CRegistry &_Registry; } After a while it turns out that not all CItem objects need to be registered so I need a version of CItem which does not requires Registry i...

Constructor overloading in Java - best practice

There are a few topics similar to this, but I couldn't find one with a sufficient answer. I would like to know what is the best practice for constructor overloading in Java. I already have my own thoughts on the subject, but I'd like to hear more advice. I'm referring to both constructor overloading in a simple class and constructor ov...

Enums, Constructor overloads with similar conversions.

Why does VisualC++ (2008) get confused 'C2666: 2 overloads have similar conversions' when I specify an enum as the second parameter, but not when I define a bool type? Shouldn't type matching already rule out the second constructor because it is of a 'basic_string' type? #include <string> using namespace std; enum EMyEnum { mbOne, mb...

Why is my overloaded C++ constructor not called?

Hi, I have a class like this one: class Test{ public: Test(string value); Test(bool value); }; If I create an object like this: Test test("Just a test..."); The bool constructor is called! Anyone knows why? Thanks ...