instantiation

Template instantiation effect on compile duration

风流意气都作罢 提交于 2019-12-23 16:14:55
问题 Writing template classes we have to inline the method bodies usually in .h files (unless instantiating them in .cpp files). We know modifying an inlined method requires recompiling the units which included them. It'll make compiling long. Another technique to implement a template class is instantiating it in a .cpp file. File Test.h : template <typename T> class Test { public: T data; void func(); }; File Test.cpp : template <typename T> void Test<T>::func() { } template class Test<float>; //

Java: Instantiating a generic class with no default constructor

放肆的年华 提交于 2019-12-23 12:27:50
问题 I am trying to do this: public class BaseTable<T extends TableEntry> { protected int mRows; protected int mCols; protected ArrayList<T> mEntries; public BaseTable(int rows, int cols) { mRows = rows; mCols = cols; mEntries = new ArrayList<T>(); for (int i = 0; i < rows; i++) { mEntries.add(new T(cols)); //this obv. doesn't work } } } Instantiating generics is hard enough as it is, but what makes this even harder is that T here does not have a default constructor, it takes a single int

Instantiate generic type in java

喜夏-厌秋 提交于 2019-12-23 08:29:12
问题 I'm stuck. Coming from C++ I thought this would simply work, but it does not. Can you please give me an advice? I will try to not end up with kind of creation method in each class used for T. public class A<T>{ private T t_; public A(){ t_ = new T(); //error } } Also i don't want to have constructor looking like: A(Class classT){ ... Ideally i would like to have something like this c++ code. template<class T> class A{ private: T t_; public: A(){} }; Thanks for help. 回答1: You cannot do such

Instantiate generic type in java

一世执手 提交于 2019-12-23 08:29:09
问题 I'm stuck. Coming from C++ I thought this would simply work, but it does not. Can you please give me an advice? I will try to not end up with kind of creation method in each class used for T. public class A<T>{ private T t_; public A(){ t_ = new T(); //error } } Also i don't want to have constructor looking like: A(Class classT){ ... Ideally i would like to have something like this c++ code. template<class T> class A{ private: T t_; public: A(){} }; Thanks for help. 回答1: You cannot do such

__callStatic(): instantiating objects from static context?

情到浓时终转凉″ 提交于 2019-12-23 07:00:16
问题 I am confused about how "static" and "dynamic" functions and objects in PHP work together especially with regards to __callStatic(). How __callStatic() works: You can have a normal class MyClass, where within the class you can put a static function called __callStatic(), which gets called only when MyClass doesn't have a static function by the name you want. i.e. I call MyClass::newFunction(); newFunction() is called statically but MyClass does not have it declared. So, then __callStatic()

Instantiation and Initialization of Value Types vs. Reference Types

匆匆过客 提交于 2019-12-23 02:07:26
问题 int number = new int(); Questions: For reference types, the new operator creates an instance of the type by allocating memory on the heap then initializes it by calling the type's constructor. As seen above, you could do the same for a value type. To me, the line above means that the constructor int() is called to initialize number with a value. I have read that int is a keyword pointing to the struct System.Int32 . Therefore, in Visual Studio, I navigate to the struct Int32. Lo and behold,

No generated code for explicitly specialized template even with explicit instantiation

℡╲_俬逩灬. 提交于 2019-12-22 05:52:33
问题 I'm getting consistent behavior from both gcc 4.8.3 and clang 3.2, but do not understand why it is happening. Despite the fact that I have an explicit instantiation for a class template, the code is not being generated and I get an undefined symbol when I am using a fully specialized instance of the template. I have a simple class template definition in a file 'temp.hpp' #pragma once template <typename T1> class C { public: C (T1 c) : d_c(c) {}; ~C () = default; void print (); private: T1 d_c

creating a global class objective-c?

梦想与她 提交于 2019-12-21 05:21:07
问题 I want to create a class in objective-c with already stored data, so that for accessing the data I don't want to instantiate the class. how can I do it? 回答1: You can use a singleton or you can use a class made only of class methods and giving you access to static data. Here is a basic singleton implementation in ObjC: @interface MySingleton : NSObject { } + (MySingleton *)sharedSingleton; @property(nonatomic) int prop; -(void)method; @end @implementation MySingleton @synthesize prop; +

Create instance of class known at runtime in Swift

戏子无情 提交于 2019-12-21 04:04:07
问题 A picture is worth a thousand words, how to rewrite this code from Objective-C to Swift? - (id) instanceOfClass: (Class) class withInitializer: (SEL) initializerSelector withObject: (id) object { id obj = nil; if([class instancesRespondToSelector:initializerSelector]) { obj = [[class alloc] performSelector:initializerSelector withObject:object]; } return obj; } id myViewController = [self instanceOfClass:[ViewController class] withInitializer:@selector(initWithObject:) withObject:@"super

Android SDK error: Trying instantiate a class that is not a fragment

只愿长相守 提交于 2019-12-20 18:02:08
问题 I am hardly trying to create a simple application with a top menu and a changeable view below (by pressing the buttons in the menu fragment we change the view of the fragment below). So, I have 2 fragments inside the main view but when trying to run the application in the emulator I get an error like: Cause by android.app (bla bla bla, piece of crap Eclipse doesn't even allow copying the errors): Trying to instantiate a class com.example.android.topmenu that is not a fragment So, these are my