Skip to main content
452 votes
14 answers
156k views

Recently I've seen an example like the following: #include <iostream> class Foo { public: int bar; Foo(int num): bar(num) {}; }; int main(void) { std::cout << Foo(42).bar << ...
nils's user avatar
  • 4,839
235 votes
9 answers
43k views

Is there any good reason that an empty set of round brackets (parentheses) isn't valid for calling the default constructor in C++? MyObject object; // ok - default ctor MyObject object(blah); // ...
Martin Beckett's user avatar
351 votes
9 answers
81k views

So, after watching this wonderful lecture on rvalue references, I thought that every class would benefit of such a "move constructor", template<class T> MyClass(T&& other) edit and of ...
Xeo's user avatar
  • 132k
276 votes
9 answers
178k views

I'm partial to using member initializer lists for my constructors, but I've long since forgotten the reasons behind this. Do you use member initializer lists in your constructors? If so, why? If not, ...
oz10's user avatar
  • 160k
407 votes
9 answers
155k views

I have a Wicket page class that sets the page title depending on the result of an abstract method. public abstract class BasicPage extends WebPage { public BasicPage() { add(new Label("...
deamon's user avatar
  • 93.3k
1125 votes
8 answers
145k views

If Test is an ordinary class, is there any difference between: Test* test = new Test; and: Test* test = new Test();
David Read's user avatar
  • 11.2k
467 votes
10 answers
1.8m views

I have some code like: class Pump: def __init__(self): print("init") def getPumps(self): pass p = Pump.getPumps() print(p) But I get an error like: Traceback (...
DominicM's user avatar
  • 6,928
51 votes
6 answers
9k views

What does the following code do: WeatherWidget.prototype = new Widget; where Widget is a constructor, and I want to extend the Widget 'class' with a new function WeatherWidget. What is the new ...
Kai's user avatar
  • 2,244
355 votes
12 answers
175k views

Suppose I have two C++ classes: class A { public: A() { fn(); } virtual void fn() { _n = 1; } int getn() { return _n; } protected: int _n; }; class B : public A { public: B() : A() {} ...
David Coufal's user avatar
  • 6,451
201 votes
5 answers
74k views

I'm trying to create a constructor for a blogging platform and it has many async operations going on inside. These range from grabbing the posts from directories, parsing them, sending them through ...
adam-beck's user avatar
  • 6,019
3774 votes
10 answers
1.3m views

What does the explicit keyword mean in C++?
Skizz's user avatar
  • 71.5k
198 votes
12 answers
524k views

What exactly is a default constructor — can you tell me which one of the following is a default constructor and what differentiates it from any other constructor? public Module() { this.name = ""; ...
antanis's user avatar
  • 1,999
894 votes
10 answers
1.1m views

What are the C++ rules for calling the base class constructor from a derived class? For example, I know in Java, you must do it as the first line of the subclass constructor (and if you don't, an ...
levik's user avatar
  • 118k
747 votes
23 answers
360k views

Java requires that if you call this() or super() in a constructor, it must be the first statement. Why? For example: public class MyClass { public MyClass(int x) {} } public class MySubClass ...
Joe Daley's user avatar
  • 46.6k
487 votes
36 answers
87k views

In JavaScript, I want to create an object instance (via the new operator), but pass an arbitrary number of arguments to the constructor. Is this possible? What I want to do is something like this (...
Prem's user avatar
  • 16.4k

15 30 50 per page
1
2 3 4 5
176