instantiation

Create an instance of a class from a string name in Haxe

孤街浪徒 提交于 2019-12-10 02:56:36
问题 Let's say i acquire the name of a class that i made as a String . How can i Instantiate the class with the name contained in that string? I I know it will be derived from a certain parent class, but the actual class will vary. 回答1: var instance : MyClass = Type.createInstance(Type.resolveClass("path.to.MyClass"), []); Few notes: resolveClass() takes the full path (packages included) of the classe you need createInstance() takes as the second argument an array of values that are applied to the

Getting the address of template class object leads to full instantiation of template parameters

别来无恙 提交于 2019-12-09 15:57:00
问题 I got the errors compiling this code with g++ 4.6 and 4.8. g++ 4.2 and 4.4 is OK. Is it a bug or some new language feature? template <typename T> struct A { typedef typename T::value_type type; }; template <typename U> struct B { void bar () { } void foo () { // OK this->bar (); // OK (*this).bar (); // Error in g++ 4.6-4.8 // leads to full instantiating of template arg "U" (&*this)->bar (); } }; int main () { B< A<void> > b; b.foo (); return 0; } g++ inst.cc inst.cc: In instantiation of

WPF Instantiate User control programmatically to render it as PNG

不羁岁月 提交于 2019-12-09 06:28:39
问题 I want to instantiate a user control programmatically in a DLL to save it afterwards as PNG file. This is generally no problem with PngBitmapEncoder and RenderTargetBitmap. This are my questions: How do I instantiate the control? Simply with the new-operator? Do I have to instantiate it in an seperate thread? How do I force the control to update all its children and to render itself again? This is my code to instantiate the user control and save it as PNG-file (LetterFrequency is the user

The impact of virtual on the use of member of class template

依然范特西╮ 提交于 2019-12-09 04:39:40
问题 I (vaguely) know that a template is not instantiated if it is not used . For example, the following code will compile fine even though T::type doesn't make sense when T = int . template<typename T> struct A { void f() { using type = typename T::type; } }; A<int> a; //ok It compiles because f() is not used , so it is not instantiated — thus the validity of T::type remains unchecked. It doesn't matter if some other member function g() calls f() . template<typename T> struct A { void f() { using

In PHP 5 can I instantiate a class dynamically?

丶灬走出姿态 提交于 2019-12-09 02:24:46
问题 Is it possible to dynamically instantiate a class using a variable? For example is something like this possible in PHP? class foo { public $something; } $class_name = "foo"; $f = new $class_name(); 回答1: That should work, yes. You can also do: $f = new $class($arg1,$arg2); 回答2: Yes, this code will work fine. 回答3: In PHP 5 can I instantiate a class dynamically? Yes you can, your code should work fine. 回答4: Yes of course you can instantiate using dynamic names; 来源: https://stackoverflow.com

How to instantiate class and init from string in Swift?

房东的猫 提交于 2019-12-08 22:51:07
问题 I could instantiate class from string in ObjC.For example,I have defined new DBCell class through subclassing UITableViewCell,and I instantiate class from name with these codes: DBCell *cell=[tableView dequeueReusableCellWithIdentifier:cellClassname]; if (cell==nil) { Class cellClass=NSClassFromString(cellClassname); cell=[cellClass alloc]; cell=[cell initWithStyle:cellStyle reuseIdentifier:cellClassname]; } Now I need migrate codes to Swift,I have redefined DBCell class in Swift: class

In Django/South HOWTO create an instance of a model from a different app during DataMigration

陌路散爱 提交于 2019-12-08 19:51:17
问题 I need to perform a datamigration of a model Answer in app Question . In that script there is a dependency such that I need to create an instance of a model Chapter which is in the app Journal . So, I coded it as follows: def forwards(self, orm): for answer_object in orm.Answer.objects.all(): #This Works. blog, is_created = orm['blog.Post'].objects.get_or_create(title=answer_object.answer[:100]) blog.save() #This DOES NOT work chapter, is_created = orm['journal.Chapter'].objects.get_or_create

Specialization of template after instantiation?

╄→尐↘猪︶ㄣ 提交于 2019-12-08 19:13:49
问题 My full code is too long, but here is a snippet that will reflect the essence of my problem: class BPCFGParser { public: ... ... class Edge { ... ... }; class ActiveEquivClass { ... ... }; class PassiveEquivClass { ... ... }; struct EqActiveEquivClass { ... ... }; struct EqPassiveEquivClass { ... ... }; unordered_map<ActiveEquivClass, Edge *, hash<ActiveEquivClass>, EqActiveEquivClass> discovered_active_edges; unordered_map<PassiveEquivClass, Edge *, hash<PassiveEquivClass>,

Class 'Room' is abstract; cannot be instantiated

瘦欲@ 提交于 2019-12-08 15:07:37
问题 I have a class an abstract class Room which has subclasses Family and Standard , I have created room = new ArrayList<Room>(); within a Hostel class. I have a method to add a room to the ArrayList; public String addRoom(String roomNumber, boolean ensuite) { if (roomNumber.equals("")) return "Error - Empty name field\n"; else room.add( new Room(roomNumber,ensuite) ); return "RoomNumber: " + roomNumber + " Ensuite: " + ensuite + " Has been added to Hostel " + hostelName; } However I get the

C++ template static member instantiation

佐手、 提交于 2019-12-08 14:47:19
问题 #include <map> #include <iostream> template <typename T> class A { static std::map<int, int> data; public: A() { std::cout << data.size() << std::endl; data[3] = 4; } }; template <typename T> std::map<int, int> A<T>::data; //std::map<int, int> A<char>::data; A<char> a; int main() { return 0; } What is wrong with this? Without explicit instantiation it breaks at data[3] = 4; Explicit instantiation solves the problem but the program breaks after std::cout << data.size() << std::endl; what means