Why does the base class constructor of a derived type get called?

The short answer for this is, “because that’s what the C++ standard specifies”. Note that you can always specify a constructor that’s different from the default, like so: class Shape { Shape() {…} //default constructor Shape(int h, int w) {….} //some custom constructor }; class Rectangle : public Shape { Rectangle(int h, int w) : … Read more

How useful would Inheriting Constructors be in C++?

2) Are there any technical reasons you can think of that would preclude “perfect forwarding constructors” from being an adequate alternative? I have shown one problem with that perfect forwarding approach here: Forwarding all constructors in C++0x . Also, the perfect forwarding approach can’t “forward” the expliciteness of base-class constructors: Either it is always a … Read more

Java/JAXB: Unmarshall Xml to specific subclass based on an attribute

JAXB is a spec, specific implementations will provide extension points to do things such as this. If you are using EclipseLink JAXB (MOXy) you could modify the Shape class as follows: import javax.xml.bind.annotation.XmlAttribute; import org.eclipse.persistence.oxm.annotations.XmlCustomizer; @XmlCustomizer(ShapeCustomizer.class) public abstract class Shape { int points; @XmlAttribute public int getPoints() { return points; } public void setPoints(int points) … Read more

Creating an interface for an abstract class template in C++

You are actually attempting the impossible. The very heart of the matter is simple: virtual and template do not mix well. template is about compile-time code generation. You can think of it as some kind of type-aware macros + a few sprinkled tricks for meta programming. virtual is about runtime decision, and this require some … Read more

How to define the default implementation of an interface in c#?

Here comes the black magic: class Program { static void Main() { IFoo foo = new IFoo(“black magic”); foo.Bar(); } } [ComImport] [Guid(“C8AEBD72-8CAF-43B0-8507-FAB55C937E8A”)] [CoClass(typeof(FooImpl))] public interface IFoo { void Bar(); } public class FooImpl : IFoo { private readonly string _text; public FooImpl(string text) { _text = text; } public void Bar() { Console.WriteLine(_text); } … Read more

Passing a pointer to a type that is privately inherited in some base class

This happens due to injected-class-name, unqualified name lookup rules and the fact the name lookup is completed before check for accessibility. injected-class-name is a mechanism that makes class name available inside that class definition. Now, the unqualified name lookup rules within a class definition state that first the scope of the class is searched, then … Read more

Value of static variable not changed even after initializing the child class in Java [duplicate]

The field y is not declared by class Checks. Reading static fields doesn’t trigger initialization of the referenced class (Checks), unless that class is the one in which the field is declared (see JLS quote below). In this example, even if y is accessed through Checks, that will only trigger the initialization of Par because … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)