constructor

StructureMap3 How to configure constructor string injection for all types?

荒凉一梦 提交于 2019-12-12 03:19:44
问题 I have registered my types using Scan( scan => { scan.TheCallingAssembly(); scan.WithDefaultConventions(); scan.With(new ControllerConvention()); }); But how do I specify for constructor injection with out having to specify the concrete type like this? string connStr = "..."; For<IRepository().Use<MyRepository>().Ctor<string>("connectionString").Is(connStr); 回答1: You can create dedicated convention for registration of repositories. public class RepositoryConvention : IRegistrationConvention {

Is javascript new keyword optional for javascript API feature?

萝らか妹 提交于 2019-12-12 03:19:06
问题 I having trouble to understand why the new keyword is facultative for javascript API object/interface feature. d = new String(); // javascript native object d2 = String(); console.log(d); console.log(d2); results in console (that seems pretty normal): String {} (an empty string) but: b = new Blob(); // API object b2 = Blob(); console.log(b); console.log(b2); results: Blob { size=0, constructor=function(), type="", more...} Blob { size=0, constructor=function(), type="", more...} and not: Blob

Constructor Parameter issue C++

孤街醉人 提交于 2019-12-12 03:12:18
问题 I have a constructor for a class that takes in a bool, a pointer to an array, and string. TheConstructor(bool theBool=true, int *theArray=0, std::string message="0"); Is this the correct way to write it in the header file? My program isn't compiling right now because of a "undefined reference to "the constructor" and to other member functions". What could be causing this also? I checked and in main.cpp I #included "Class.h" and defined every memberwise function that needed to be defined that

C++ Vector Arrays in Copy Constructors

六眼飞鱼酱① 提交于 2019-12-12 03:08:23
问题 I am new to copy constructors and can't seem to get them working when I start using vectors. // ROBOT CLASS class Robot { private: char *name; int size; int cmdCount; command *cmdList; char items[8][16]; int resources[3]; // silver, gold, then platinum public: Robot( ); Robot(int num_of_cmds, const char *nm); Robot(const Robot &); ~Robot( ); const char *get_name( ); command get_command(int pos) const; void set_item(const char item[ ], int pos); const char *get_item(int pos); }; // ROBOT

Auto-constructor not working with <functional> objects

无人久伴 提交于 2019-12-12 02:56:27
问题 Consider the following code: class _c { public: _c(int); _c(function<void(void)>); }; A class with two constructors defined for an int and a function<void(void)> respectively. Which means that I can now instantiante objects of those class like this: _c a = _c(0); _c b = _c([]() {}); Now, I declare a function that takes a _c object as an argument: void _f(_c __c) {}; And now I can call this function with my _c objects like this: _f(_c(0)); _f(_c([]() {})); Until here, everything looks good.

Calling a subclass constructor from a superclass

浪子不回头ぞ 提交于 2019-12-12 02:44:55
问题 I am first encountering inheritance in java and I have an issue with constructors. Consider class A class A{ ...(Constructor) { ... ObjectCreatedBySubClass= new B(); } ...(etc) protected static B ObjectCreatedBySubClass; } Along with its subclass class B extends A{ B(){ ..(No matter what code I put here, it does not work.) } ...(Instance variables) } No matter what I change, every time I get Exception in thread "main" java.lang.StackOverflowError at A.<init> at B.<init> (repeat about 100

constructors of my string C++

本秂侑毒 提交于 2019-12-12 02:42:49
问题 I know that if something in the constructor fails, I must throw an exception. Does this mean everytime I use 'new' inside of my constructors, when I create an object of this class I should initialise it in the 'try' 'catch' block? try{ mystring s("test"); } catch(std::ba .....) {...........} I know that is almost impossible 'new' to fail, but what I'm asking is, if my constructor throws something, is this the right way to catch it? (because I've never seen someone using it when creating an

Can we declare __constructor and class name constructor in same class?

巧了我就是萌 提交于 2019-12-12 02:35:03
问题 Can we declare __constructor and class name constructor in same class? If yes, does both get called when object gets created. Also what will be the sequence. If only one will get called then which one? and Why? 回答1: Further down this answer you'll find your individual questions answered in a handy list format. But first, allow me to give you some general information, documentation quotes, links and code snippets that'll help you understand all this a bit better. You can define both types of

Initialize member functions via constructor

倖福魔咒の 提交于 2019-12-12 02:23:30
问题 Perhaps I am way out of left field with this question, but is it possible to define a member function via the constructor? In my case, I am trying to write a class to perform robust model fitting (using RANSAC). I want this to be generalizable to different types of models. For example, I could use this to determine an estimate of a plane to a set of 3D points. Or, perhaps I could determine a transformation between two sets of points. In these two examples, there might need to be different

Non-default constructors for COM objects

大憨熊 提交于 2019-12-12 02:18:39
问题 How do you define a non-default constructor for a COM object in Visual C++? Is such a thing even possible? Or do you have to construct a default object and use an init(params) method to configure it? 回答1: COM coclasses implemented in C++ cannot have a constructor that takes an argument. The CoCreateObject() function, the primary way to create an instance of a coclass, doesn't have any way to pass arguments. Same with IClassFactory::CreateInstance(), the underlying method. So yes, not possible