constructor

__do_global_dtors_aux and __do_global_ctors_aux

你说的曾经没有我的故事 提交于 2020-01-29 04:54:24
问题 I disassembled a simple program written in C++ and there are these two function names. I guess that ctor means constructor and dtor means destructor, and word global maybe means that they create and destroy global objects. I cannot guess the name aux. What do these two functions do? 回答1: The addresses of constructors and destructors of static objects are each stored in a different section in ELF executable . for the constructors there is a section called .CTORS and for the destructors there

Return Statement in JS Constructors

雨燕双飞 提交于 2020-01-29 03:52:05
问题 What is the effect of a return statement in the body of JavaScript function when it's used as a constructor for a new object(with 'new' keyword)? 回答1: Usually return simply exits the constructor. However, if the returned value is an Object, it is used as the new expression's value. Consider: function f() { this.x = 1; return; } alert((new f()).x); displays 1, but function f() { this.x = 1; return { x: 2}; } alert((new f()).x); displays 2. 回答2: The reason to use the new operator is to ensure

Return Statement in JS Constructors

邮差的信 提交于 2020-01-29 03:51:09
问题 What is the effect of a return statement in the body of JavaScript function when it's used as a constructor for a new object(with 'new' keyword)? 回答1: Usually return simply exits the constructor. However, if the returned value is an Object, it is used as the new expression's value. Consider: function f() { this.x = 1; return; } alert((new f()).x); displays 1, but function f() { this.x = 1; return { x: 2}; } alert((new f()).x); displays 2. 回答2: The reason to use the new operator is to ensure

c++ how does a class derived from a template call the template's constructor?

左心房为你撑大大i 提交于 2020-01-25 12:47:48
问题 I didn't really know how to call this thread. The situation is the following. I have a template class Array<T> : template <typename T> class Array{ private: T* m_cData; int m_nSize; static int s_iDefualtSize; public: Array(); Array(int nSize); } Now, I would like to write a specialized class derived from Array<T> , holding objects of class Boxes : class Boxes{ private: double m_dFull; public: Boxes(double dFull=0): m_dFull(dFull) {} }; I do that in the following manner: class BoxesArray :

IDE thinks functor is a constructor?

被刻印的时光 ゝ 提交于 2020-01-25 06:56:10
问题 I am trying to write an implementation of primms algorithm for a DSA class. There are some nuances to make the project a little trickier (some points cannot be reached by others based on the 'terrain' at that location) so I made a functor to get distances (edge weights). My functor looks like this class primms_distance{ double operator ()(const primms_vertex &a, const primms_vertex &b){ //ommitted for University honor code purposes } }; However, I later do the following (again simplified for

Why doesn't a constructor accept parameters of a class with lower accessibility?

妖精的绣舞 提交于 2020-01-25 00:32:07
问题 Here it is: I have two Forms and one Class, I want to pass the instance of this Class from Form1 to Form2 through a parameter (which belongs to the second form's constructor). public partial class Form1 : Form { Class1 cl = new Class1(); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Form2 frm_2 = new Form2(cl); } } Thus, I receive the folowing error: Inconsistent accessibility: parameter type 'WindowsFormsApplication1.Class1' is less

Android custom arrayadapter constructor issue

删除回忆录丶 提交于 2020-01-25 00:12:07
问题 I am making a custom arrayAdapter for my listview, but a simple thing like my super constructor is messing me up! private ArrayAdapter<ScheduleTime> timeHold; //make proper constructor, see use ticket types public TimeTableAdapter(Context context, int textViewResourceId, ArrayAdapter<ScheduleTime> timesTable) { super(context, textViewResourceId, timesTable); this.timeHold = timesTable; } I get the error on the super line: super(context, textViewResourceId, timesTable); The constructor

What is a difference between an object literal and a class with values in constructor in javascript?

落爺英雄遲暮 提交于 2020-01-24 21:49:11
问题 I've been working on end to end test in testcafe and in their documentation I found following solution for Page Model: class Page { constructor () { this.nameInput = Selector('#developer-name'); } } export default new Page(); I've been doing some research and I cannot get my head around why it is not resolved with an object literal: export const Page = { nameInput: Selector('#developer-name'); } What are consequences of using each of them? 回答1: The difference is significant but fundamentally

How to pass method result as parameter to base class constructor in C++?

£可爱£侵袭症+ 提交于 2020-01-24 19:05:30
问题 I've trying to achieve something like this: class Base { public: Base(string S) { ... }; } class Derived: Base { public: int foo; string bar() { return stringof(foo); // actually, something more complex }; Derived(int f) : foo(f), Base(bar()) { }; } Now, this doesn't work as I want, because bar() is called in the Derived constructor before foo is initialized. I considered adding a static function similar to bar() which takes foo as a parameter - and using that in the initialization list, but

C++ - Constructing wrapper class with same syntax as wrapped data

我怕爱的太早我们不能终老 提交于 2020-01-24 12:32:57
问题 I'm making a template class that is a wrapper around some type of data. I would like to be able to set / construct this class the same way as I set that data when it's not wrapped. Here's the basic idea: template<typename T> class WrapperClass{ public: T data; WrapperClass(const T& _data) : data( _data) {} // others stuff }; Now with something like an integer, I can do this: WrapperClass<int> wrapped_data = 1; But with a struct or class I don't know how: struct SomeStruct{ int a, b, c;