instantiation

C++ Pointers and Object Instantiation

杀马特。学长 韩版系。学妹 提交于 2019-12-24 09:55:39
问题 This works: MyObject *o; o = new MyObject(); And this does not: MyObject o = new MyObject(); Why? 回答1: The keyword new returns a pointer. It must be assigned to a pointer of an object. This would also work: MyObject o = MyObject(); EDIT: As Seth commented, the above is equivalent to: MyObject o; The default constructor (i.e. without parameters) is called if no constructor is given. 回答2: Because they're not equivalent. Try: MyObject* o = new MyObject(); 回答3: new MyObject() returns a pointer to

Inner class within its abstract superclass in Kotlin?

喜夏-厌秋 提交于 2019-12-24 09:47:50
问题 If a set of inner classes are the only implementations (subclasses) of their outer abstract containing class, how does one instantiate them? abstract class A { inner class A1 : A() inner class A2 : A() } In other words, what is the syntax to construct an instance of A1 or A2 ? EDIT: ... outside the body of class A. 回答1: Are you looking for this? abstract class A { fun doSome() { // OK val a1 = A1() val a2 = A2() } inner class A1 : A() inner class A2 : A() } I think you probably want to

Dll does not seem to be read, why?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 07:55:12
问题 I am creating a application form to view/change a tag from a software called InTouch. I added the dll as a reference and I would like to use the Read(string tagName ) fct in the IOM.InTouchDataAccess. VS does not see the fct Read when I write InTouchWrapper TagType = new read() . It only sees InTouchWrapper as I wrote in the code which gives me the error IOM.InTouchDataAccess.InTouchWrapper' does not contain a constructor that takes 0 arguments I don't understand why is this happening. I am

Limit the number of DIRECT Instances of a class

心不动则不痛 提交于 2019-12-24 04:59:09
问题 To put in other words: How can a class track whether its constructor is called due to instantiating its child class or its instance is directly created? [Please cosider the following sample code]: class Parent { ............. ......... .............. } class Child1 extends Parent { ............. ......... .............. } class Child2 extends Parent { ............. ......... .............. } I want to limit number of direct instances of Parent class created by calling new Parent(...) , and

PHP: Instantiating a class from a variable oddly fails

久未见 提交于 2019-12-24 03:12:53
问题 I'm trying to instantiate a class (a Laravel3 Eloquent model) by a variable, and I'm getting an error saying that the class is not found. When I hardcode the class name, though, it works just fine. (FYI, in the code below $contact_type is expected to either be Phone, Fax, or Email.) Here's what I'm playing with at the moment: foreach( $input AS $contact_type => $contact_info ) { foreach( $contact_info AS $data ) { $obj = new $contact_type( (array)$data); echo'<pre>Obj: ',print_r($obj),'</pre>

explicit instantiation of parameterized template methods

a 夏天 提交于 2019-12-24 00:33:16
问题 I've two different template classes, one of them using as parameter an object of the another template class. i'm getting an error message: collect2: ld returned 1 exit status make: * [main] Error 1 I'm working with explicit instantiation of templates and I found some related posts but they were mostly related to instantiations of one single template class. In my case, I've 3 files per class (.h, .cpp, .inc following http://www.parashift.com/c++-faq/templates.html#faq-35.13 suggestion). foo.h

Prevent instantiation of template class with an incomplete type

强颜欢笑 提交于 2019-12-23 19:34:14
问题 I'm writing a library. Its layout looks something akin to this: ///////// // A.h // ///////// #include <vector> class B; class A { std::vector<B> Bs; public: ... }; ///////// // B.h // ///////// class B { ... } /////////// // A.cpp // /////////// #include "A.h" #include "B.h" // Implementation of A follows ... /////////// // B.cpp // /////////// #include "B.h" // Implementation of B follows ... ///////////// // MyLib.h // ///////////// #include "A.h" As you can see, the only type accessible

In swift, why can't I instantiate a protocol when it has an initialiser?

情到浓时终转凉″ 提交于 2019-12-23 18:06:49
问题 I understand that generally I cannot instantiate a protocol. But if I include an initialiser in the protocol then surely the compiler knows that when the protocol is used by a struct or class later, it will have an init which it can use? My code is as below and line: protocol Solution { var answer: String { get } } protocol Problem { var pose: String { get } } protocol SolvableProblem: Problem { func solve() -> Solution? } protocol ProblemGenerator { func next() -> SolvableProblem } protocol

Instantiation of ill-formed non-templated method of a templated class

£可爱£侵袭症+ 提交于 2019-12-23 17:18:17
问题 I was researching on two phase name lookup. A very logical explanation shows that one of the main reasoning for it is that follows the C++ philosophy of catching errors as early as possible . My question is why isn't this philosophy followed with non-templated methods. Instead of checking when and if the method is called, why not check all non-templated methods in phase 2 when the templated class is instantiated? E.g.: template <class T> struct X { auto foo() // non-templated (important) { T

How can I use Scala's Manifest class to instantiate the erased class at runtime?

寵の児 提交于 2019-12-23 16:33:04
问题 I'm doing some WebDriver+PageObject stuff. (If your not familiar with PageObjects, this is a pattern where you have a class representing each page on your site which exposes all the functions of the page using the domain language, hiding the HTML stuff from the test.) I want to be lazy and have one 'submit' method in my abstract Page class that all my other Pages extend from. I also want this method to new up the next Page subclass and return it. Here is what I have in the Page class: def