instantiation

Create subclass from superclass static main

江枫思渺然 提交于 2020-01-03 19:04:34
问题 I have a generic, abstract class ( SuperClass ). I want to have there a main method, that would be a default main for each subclass and would do the same, but with proper subclass object that derived and called it. Like this: public abstract class SuperClass { // some code here... public static void main(String args[]) { // here instantiate the subclass // extending this SuperClass, and call // some methods } } public SubClass extends SuperClass { // here just implement some // abstract

Template specialization doesn't see a function in its point of instantiation

拜拜、爱过 提交于 2020-01-03 16:52:31
问题 I don't understand why it isn't correct #include <iostream> using namespace std; struct CL{}; template <typename T> void fnc(T t) { f(t); } namespace NS { void f(CL){} void fn() {fnc(CL()); /*error is here*/} //point of instantiation fnc<CL> is here (in namespace scope, //according to 14.6.4.1/1) } int main(){} Calling f(t) in template function fnc is dependent on template parameter and then name lookup must be at an instantiation point. I saw Standard (C++ 14) 14.6.4.1/1 For a function

Semantic correctness of non-instantiated C++ template functions

谁说胖子不能爱 提交于 2020-01-02 04:51:06
问题 The following C++ code does not compile e.g. with g++-4.7 or clang++-3.2: struct Bar {}; template<typename T> void foo(T t, Bar bar) { t.compiler_does_not_care(); bar.nonexistent_method(); } int main() {} Why do compilers check the code of the template function foo for semantic correctness (where they can) even though it is never instantiated? Is this standard compliant? 回答1: Bar is a non dependent name (i.e. its type does not depend on T ), so the compiler is required to verify the

When instantiating a (sub)Class, is there any difference in what “type” you declare the object as?

瘦欲@ 提交于 2020-01-01 18:30:34
问题 Say I have a Class called ParentClass and a Class called ChildClass The ParentClass is abstract and the ChildClass extends the ParentClass per Java terminology. Furthermore, the ParentClass has a constructor which takes an int as a parameter. Now in another class I want to instantiate the ChildClass . I have tried the two below ways: ChildClass obj1 = new ChildClass(5) ParentClass obj2 = new ChildClass(5) Java allows me to use any of the two above ways. My question is, is there actually any

Preventing class instantiation from other classes

谁都会走 提交于 2019-12-31 02:49:35
问题 I'm working with a domain, view and controllers. Each containing their own classes. The domain contains a lot of classes that should not be instantiated in classes outside of the domain. I was under the impression the default access modifier was going to help me. Making my domain classes their constructors package visible. Turns out any class can still use the constructors after importing the right package.class file. How can I prevent this from happening? 回答1: When you say 'Turns out any

Profiling template metaprogram compilation time

萝らか妹 提交于 2019-12-29 04:34:25
问题 I'm working on a C++ project with extensive compile-time computations. Long compilation time is slowing us down. How might I find out the slowest parts of our template meta-programs so I can optimize them? (When we have slow runtime computations, I have many profilers to choose from, e.g. valgrind's callgrind tool. So I tried building a debug GCC and profiling it compiling our code, but I didn't learn much from that.) I use GCC and Clang, but any suggestions are welcome. I found profile

Android Viewpager saving data and views

老子叫甜甜 提交于 2019-12-29 03:59:59
问题 Hopefully someone can help me with a slight problem/confusion I have with Viewpagers and saving data. PROBLEM: When scrolling across the four views I have, the first view has two spinners, two textviews that display a string or a selected item. if I scroll on to the third page and back to the second page, the data in the first view is lost. hense needing to save the data. Would this be done in the two routines stated below? (best guess is it would be) if so, what sort of commands need to be

how to instantiate an object of class from string in Objective-C?

空扰寡人 提交于 2019-12-28 13:40:53
问题 I've a String who's value is the name of the Class[MyClass] which has to be instantiated, and MyClass has a method called -(void)FunctionInClass; i'm using the method called NSClassFromString to instantiate MyClass.I want to know 1) what does NSClassFromString return?? 2) what is id? 3) How to call method -(void)FunctioninClass which is in MyClass using the instance. how should i proceed , i'm doing it in Objective-C for iPhone app? 回答1: 1) what does NSClassFromString return?? It returns a

Instantiate a class from its textual name

旧街凉风 提交于 2019-12-28 02:04:59
问题 Don't ask me why but I need to do the following: string ClassName = "SomeClassName"; object o = MagicallyCreateInstance("SomeClassName"); I want to know how many ways there are to do this is and which approach to use in which scenario. Examples: Activator.CreateInstance Assembly.GetExecutingAssembly.CreateInstance("") Any other suggestions would be appreciated This question is not meant to be an open ended discussion because I am sure there are only so many ways this can be achieved. 回答1:

instantiated object's method won't run, error "variable(object's name) not initialized

流过昼夜 提交于 2019-12-25 17:17:33
问题 /** There seems to be a problem with the intended method call from the performance class. The object is recognized as band but for some reason when i call band.begin() (band is the new performance object and begin its method) band is not recognized and it suggests it be initialized as a variable? */ import java.util.Scanner; public class Music { public static Instrument assignInstrument () { String instrumentChoice; String name; Scanner input = new Scanner (System.in); System.out.println(