constructor

When is the `.constructor` property of an object actually used

久未见 提交于 2019-12-24 01:09:52
问题 I've been using code like this for inheriting from another object: // define base object constructor function SuperType(){ // constructor code } // define base object methods on the prototype SuperType.prototype.foo = function() {}; // --------------------------------------------------------------------------- // define object that wants to inherit from the SuperType object function SubType() { // call base object constructor with all arguments that might have been passed SuperType.apply(this

backbone + rails TypeError: List.Header is not a constructor

别来无恙 提交于 2019-12-24 01:08:59
问题 I am trying to follow along with the tutorial I purchased from this site: http://www.backbonerails.com/ I am following along with the 5th episode of the series, "Getting Up and Running - Part 1". At about the 46:52 mark of the video he has this code for "list_controller.js.coffee". @Demo.module "HeaderApp.List", (List, App, Backbone, Marionette, $, _) -> List.Controller = listHeader: -> console.log "header" When I have this...everything works...the console reads "header". At about the 47:20

cannot find constructor in C++ templated code [duplicate]

给你一囗甜甜゛ 提交于 2019-12-24 00:59:15
问题 This question already has answers here : Why can templates only be implemented in the header file? (16 answers) Closed 6 years ago . I am getting this error when compiling it with: g++ main.cpp Vec.cpp -Wall -o main -I. /tmp/cciqbEQJ.o: In function `main': main.cpp:(.text+0x8b): undefined reference to `Vec<double>::Vec()' main.cpp:(.text+0x9b): undefined reference to `Vec<double>::~Vec()' collect2: ld returned 1 exit status make: *** [all] Error 1 I don't understand because I have done a lot

Reference Scala constructor args in default value

十年热恋 提交于 2019-12-24 00:56:20
问题 In the following Scala code, the compiler is telling me not found: value x when I try to new up my default value for y , referencing x , another constructor argument. class Foo(x: String, y: Bar = new Bar(x)) class Bar(a: String) I trust there's good reason for this limitation. Can anyone shed some light and possibly offer an alternative approach? 回答1: As an alternative approach: class Foo(x: String, y: Bar) class Bar(a: String) object Foo { def apply(x: String) = new Foo(x, new Bar(x)) }

C# related on Constructor and Property

江枫思渺然 提交于 2019-12-24 00:48:12
问题 I am building some tiny lib, and I have run into a problem. I want to provide a two-way solution, for example: How can I accomplish this? I am getting exception thrown, because it expects something... Any example that will do is welcomed :) Thanks! EDIT: I am executing something, initially my code is similar to this one: System.IO.DriveInfo d = new System.IO.DriveInfo("C:"); I want to achieve with my class the following: Driver d = new Driver(); d.DriverLetter = "C:"; And still get the same

Object Constructor Call Not Declared In This Scope

…衆ロ難τιáo~ 提交于 2019-12-24 00:47:09
问题 I have managed to solve this myself by moving the #include for part_time.h to the top of the #include list. Why this made a difference, I have no idea. I'm having an issue with one manual object construct call after splitting my program into a makefile . Each .cpp has an include for it's .h, and main.cpp includes every .h as well. The relevant code is below. The errors are: main.cpp: In function ‘void add_part_time()’: main.cpp:166:2: error: ‘part_time’ was not declared in this scope part

Object Constructor Call Not Declared In This Scope

六月ゝ 毕业季﹏ 提交于 2019-12-24 00:41:47
问题 I have managed to solve this myself by moving the #include for part_time.h to the top of the #include list. Why this made a difference, I have no idea. I'm having an issue with one manual object construct call after splitting my program into a makefile . Each .cpp has an include for it's .h, and main.cpp includes every .h as well. The relevant code is below. The errors are: main.cpp: In function ‘void add_part_time()’: main.cpp:166:2: error: ‘part_time’ was not declared in this scope part

How objects are created when the prototype of their constructor isn't an object?

て烟熏妆下的殇ゞ 提交于 2019-12-24 00:29:06
问题 I answered this question: How do objects created? but I also have a question after I answered it. function Bar() { this.foo = true; } console.log('obj3'); Bar.prototype = 3; var obj3 = new Bar(); console.log(obj3); console.log(obj3.constructor === Bar); console.log(obj3.constructor === Object); console.log(Object.prototype === Object.getPrototypeOf(obj3)); console.log(obj3.foo); Bar.prototype = 3 , my theory is that, when new Bar() executed, as in Step 2 , the created object is supposed to

Invoke another constructor in the same class

倾然丶 夕夏残阳落幕 提交于 2019-12-24 00:08:57
问题 I have a class with 2 public constructors, that I want to call a private constructor: class CDeviceTSGetObservationResponse : public CDeviceServerResponse { public: /** * Public constructor. Used to construct a response containing * the required information from the TotalStation device. * * @param horizontalAngle * The horizontal angle. * @param verticalAngle * The vertical angle. * @param slopeDistance * The slope distance. */ CDeviceTSGetObservationResponse(double horizontalAngle, double

c++ how to write a constructor?

核能气质少年 提交于 2019-12-24 00:08:45
问题 I'm not used to c++ and I'm having a problem writing a constructor. See this example, is a short version of the code I'm working on: class B { public: B(int x); } class A { public: B b; A(){ // here I have to initialize b } } That throws a compiler error since I need to initialize b in A's constructor because B does not have a default constructor. I think I have do it in the initialization list, but the B(int x) argument is a value I have to calculate with some algorithm, so I don't know how