Whats the utility of public constructors in abstract classes in C#?

Absolutely correct. You should favor the protected constructor. EDIT: no the compiler doesn’t complain, but tools like FxCop (& Code Analysis) do. I believe there are some weird reflection tricks you can do with public constructors on abstract classes, but from a standpoint where you are merely providing base class functionality to other developers writing … Read more

When to make constructor explicit in C++ [closed]

The traditional wisdom is that constructors taking one parameter (explicitly or effectively through the use of default parameters) should be marked explicit, unless they do define a conversion (std::string being convertible from const char* being one example of the latter). You’ve figured out the reasons yourself, in that implicit conversions can indeed make life harder … Read more

Is it possible to have a constructor template with no parameters?

There is no way to explicitly specify the template arguments when calling a constructor template, so they have to be deduced through argument deduction. This is because if you say: Foo<int> f = Foo<int>(); The <int> is the template argument list for the type Foo, not for its constructor. There’s nowhere for the constructor template’s … Read more

Why can’t the default constructor be called with empty brackets?

Most vexing parse This is related to what is known as “C++’s most vexing parse”. Basically, anything that can be interpreted by the compiler as a function declaration will be interpreted as a function declaration. Another instance of the same problem: std::ifstream ifs(“file.txt”); std::vector<T> v(std::istream_iterator<T>(ifs), std::istream_iterator<T>()); v is interpreted as a declaration of function with … 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

How to store objects without copy or move constructor in std::vector?

For the start, std::mutex can not be copied or moved, therefore you are forced to use some kind of indirection. Since you want to store mutex in a vector, and not copy it, I would use std::unique_ptr. vector<unique_ptr<T>> does not allow certain vector operations (such as for_each) I am not sure I understand that sentence. … Read more