constructor

Javascript constructor - Use an object?

為{幸葍}努か 提交于 2019-12-11 01:56:52
问题 I'm trying to create a new object by using an already made object. This is what I am trying to achieve: var obj = {"Name" : "Patrick", "Age": 25, "Country": "US"}; document.writeln(JSON.stringify(obj) + "<br />"); function Person(name, age, country) { this.name = name; this.age = age; this.country = country; } document.writeln(JSON.stringify(new Person(obj))); https://jsfiddle.net/dotjz9tb/ As you can see, I am trying to create a new person called Patrick, aged 25, who happens to live in the

How many instances and references are created for a Base-Sub Class?

五迷三道 提交于 2019-12-11 01:45:17
问题 In C# .NET, I have 2 concrete classes. Class A and B. Class B is a subclass of Class A. How many instances (objects on the heap) and references from the stack to the heap objects are created for each line of code: ClassB b = new ClassB(); ClassA a = new ClassB(); 回答1: Going with the analogy that the object is a balloon and the reference is a string that is tied to the baloon, in each of the following cases there would be one balolon and one string: ClassB b = new ClassB(); //one reference,

C++ nested constructor calls vs. function declaration

左心房为你撑大大i 提交于 2019-12-11 01:43:05
问题 What is the difference between the code snippets labeled "version 1" and "version 2" in the following code section: int main() { using namespace std; typedef istream_iterator<int> input; // version 1) //vector<int> v(input(cin), input()); // version 2) input endofinput; vector<int> v(input(cin), endofinput); } As far as I understand "version 1" is treated as function declaration. But I don't understand why nor what the arguments of the resulting function v with return type vector<int> are.

Calling the Constructor for the Abstract Base class in C++

烈酒焚心 提交于 2019-12-11 01:40:10
问题 I know that the if I have an abstract class then I cannot create an object of abstract class type. But Suppose "Base" is a base class and "Derived" is a derived class. In base class I have one member variable name. Base.h Base(string name = ""); Base.cpp Base(string theName){name = theName); Isn't this creating an object ?? In the Derived class I have member variable age. Now in the derived class default constructor Derived.h Derived(string name = "", int theAge = 0); Derived.cpp Derived

Preferred parameter passing for constructors

江枫思渺然 提交于 2019-12-11 01:35:10
问题 Is there a preferred practice for passing constructor parameters? In particular if those constructor parameters are used to initialize member variables. A simplified example. class Example { public: Example( /*type-1*/ str, /*type-2*/ v ): m_str( str ), m_v( v ) { } /* other methods */ private: std::string m_str; std::complex<float> m_v; }; The options are: pass-by-value, then std::move the object into the member. const& , then copy the parameter into the member. && , then initialize the

Do I really need to implement user-provided constructor for const objects?

烈酒焚心 提交于 2019-12-11 00:46:59
问题 I have the code: class A { public: A() = default; private: int i = 1; }; int main() { const A a; return 0; } It compiles fine on g++ (see ideone), but fails on clang++ with error: default initialization of an object of const type 'const A' requires a user-provided default constructor I reported this issue on LLVM bug-tracker and got it INVALID. I see it absolutly pointless to try to convince the clang developers. On the other side, I don't see the reason for such restriction. Can anyone

Delphi Form with custom constructor as the mainform?

旧时模样 提交于 2019-12-11 00:42:37
问题 I want to have a MainForm that is derived from a BaseForm that has a custom constructor. Since this is the Mainform, it is created by a call to Application.CreateForm(TMyMainForm, MyMainForm) in the *.dpr file. However, my custom constructor is not called during form creation. Obviously, it works fine, if I call MyMainForm := TMyMainForm.Create(AOwner) . Can I not use a form with custom constructor as the main form ? TBaseForm = class(TForm) constructor Create(AOwner:TComponent; AName:string)

Copy/move elision versus explicitly deleted copy/move constructors

青春壹個敷衍的年華 提交于 2019-12-11 00:29:56
问题 I want to know when copy/move elision applies (or is allowed to apply) to explicitly delete d copy/move constructors and to non- delete d copy/move constructors. Here are the specifics: Can an explicitly delete d copy ctor or move ctor get elided? Is an attempt to construct an object from another same-type object or temporary object ever allowed to succeed by skipping over the delete d copy ctor and/or delete d move ctor? Here’s what happens in VC12 (with which I’m not sure if there is an

In javascript, what is a constructor? And what isn't?

心已入冬 提交于 2019-12-11 00:24:47
问题 I'm using a plugin for jQuery. It works great in webkit, but when I try it in firefox I get the following firefox error: google.maps.Geocoder is not a constructor $('.to, .from').geo_autocomplete(new google.maps.Geocoder, { Here is all the jquery: $('.to, .from').geo_autocomplete(new google.maps.Geocoder, { mapkey: 'ABQIAAAAbnvDoAoYOSW2iqoXiGTpYBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQNumU68AwGqjbSNF9YO8NokKst8w', selectFirst: false, minChars: 3, cacheLength: 50, width: 235, scroll: true, scrollHeight:

Pybind11: passing a string* argument to a constructor

眉间皱痕 提交于 2019-12-11 00:24:32
问题 In a C++ library that I'm not allowed to change I have a constructor that looks like this: Dfa(const int n_state, const int dim_alf, const string *alf); If I simply bind with .def(py::init<const int, const int, const std::string*>()) it compiles succesfully. The problem is that I can't pass a string* by python, because for example if I try to execute on python alph=['x','y'] z=Dfa(3,2,alph) It returns the following error: TypeError: __init__(): incompatible constructor arguments. The