instantiation

Why do I get an error instantiating an interface?

試著忘記壹切 提交于 2019-11-27 05:32:39
问题 I have a class and an interface, and when I try to instantiate the interface, I get an error: Cannot create an instance of the abstract class or interface My code is below: namespace MyNamespace { public interface IUser { int Property1 { get; set; } string Property2 { get; set; } string Property3 { get; set; } void GetUser(); } public class User : IUser { public int Property1 { get; set; } public string Property2 { get; set; } public string Property3 { get; set; } public void GetUser() { /

Instantiate a class from its textual name

為{幸葍}努か 提交于 2019-11-27 04:35:32
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. Here's what the method may look like: private static object MagicallyCreateInstance(string className) { var

What makes my.class.js so fast? [closed]

让人想犯罪 __ 提交于 2019-11-27 04:08:37
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . I've been looking at the source code of my.class.js to find out what makes it so fast on Firefox. Here's the snippet of code used to create a class: my.Class = function () { var len = arguments.length; var body = arguments[len - 1]; var SuperClass = len > 1 ? arguments[0] :

Instance member cannot be used on type

无人久伴 提交于 2019-11-27 04:08:34
I have the following class: class ReportView: NSView { var categoriesPerPage = [[Int]]() var numPages: Int = { return categoriesPerPage.count } } Compilation fails with the message: Instance member 'categoriesPerPage' cannot be used on type 'ReportView' What does this mean? Daniel Krom You just have syntax error when saying = {return self.someValue} . The = isn't needed. Use : var numPages: Int { get{ return categoriesPerPage.count } } if you want get only you can write var numPages: Int { return categoriesPerPage.count } with the first way you can also add observers as set willSet & didSet

How does one instantiate an array of maps in Java?

僤鯓⒐⒋嵵緔 提交于 2019-11-27 04:00:36
问题 I can declare an array of maps using generics to specify the map type: private Map<String, Integer>[] myMaps; However, I can't figure out how to instantiate it properly: myMaps = new HashMap<String, Integer>[count]; // gives "generic array creation" error myMaps = new HashMap[count]; // gives an "unchecked or unsafe operation" warning myMaps = (Map<String, Integer>[])new HashMap[count]; // also gives warning How can I instantiate this array of maps without getting a compiler error or warning?

no enclosing instance of type… in scope

☆樱花仙子☆ 提交于 2019-11-27 03:26:55
问题 I investigate java inner classes. I wrote example: public class Outer { public Outer(int a){} public class Inner { public Inner(String str, Boolean b){} } public static class Nested extends Inner{ public static void m(){ System.out.println("hello"); } public Nested(String str, Boolean b , Number nm) { super("2",true); } } public class InnerTest extends Nested{ public InnerTest(){ super("str",true,12); } } } I invoke it from main using following string: new Outer(1).new Inner("",true); I see

Automatically count the number of instantiated classes in a TMP?

女生的网名这么多〃 提交于 2019-11-27 02:17:51
问题 Given a template metaprogram (TMP), do C++ compilers produce build statistics that count the number of instantiated classes? Or is there any other way to automatically get this number? So for e.g. the obiquitous factorial #include <iostream> template<int N> struct fact { enum { value = N * fact<N-1>::value }; }; template<> struct fact<1> { enum { value = 1 }; }; int main() { const int x = fact<3>::value; std::cout << x << "\n"; return 0; } I would like to get back the number 3 (since fact<3>,

Instantiating object from inside the main of that class in Java

穿精又带淫゛_ 提交于 2019-11-27 01:56:35
问题 I was looking through my OOP class documentation and I found this example: class Student { private String name; public int averageGrade; public Student(String n, int avg) { name = n; averageGrade = avg; } public static void main(String[] args) { Student s = new Student("John", 9); } } I find it confusing that they are instantiating an object from the main of the same class. Is this considered bad practice? Will the newly created object s have a main method? Thank you! 回答1: There's nothing

cannot instantiate a class using a button

删除回忆录丶 提交于 2019-11-26 21:42:56
问题 I am trying to make a screen capturing program. What I have is a transparent window, which will give the area to be captured, with a button capture on it, and I am trying to instantiate a class captureScreen that works good when captureScreen is individually executed using a command prompt I am trying to instantiate this captureScreen class when button capture is hit. I have tried keeping this class on my screenrecord.java , putting the code in event listener also. In both these cases,I get

class template instantiation

江枫思渺然 提交于 2019-11-26 20:56:28
问题 I just read the wiki article about CRTP, and I'm a little confused about template instantiation. According to the wiki, member function bodies (definitions) are not instantiated until long after their declarations. I don't quite understand what it means. Suppose I got a class template: template <typename T> class A { public: void foo(T t) { //... }; }; When I instantiate the class template A, does it instantiate the member function foo()? For example: //in .cpp file int main() { A<int> a; /