Questions tagged [instantiation]

Instantiation is the process of creating objects from a class in most object oriented and object based languages. In the C++ language, instantiation is the process of creating a class or function from a class template or function template.

2609 questions
20
votes
1 answer

java override during object creation

in the following java code a JButton is created but at the same time one of its methods gets overridden. Qestion: is there a name for overriding in this way while creating the object? the code: JButton myButton; myButton = new JButton…
karl
19
votes
5 answers

Instantiate an object without calling its constructor in PHP

To restore the state of an object which has been persisted, I'd like to create an empty instance of the class, without calling its constructor, to later set the properties with Reflection. The only way I found, which is the way Doctrine does, is to…
BenMorel
  • 34,448
  • 50
  • 182
  • 322
19
votes
3 answers

__callStatic(): instantiating objects from static context?

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…
Dennis
  • 7,907
  • 11
  • 65
  • 115
18
votes
3 answers

What am I doing wrong? Python object instantiation keeping data from previous instantiation?

Can someone point out to me what I'm doing wrong or where my understanding is wrong? To me, it seems like the code below which instantiates two objects should have separate data for each instantiation. class Node: def __init__(self, data = []): …
KobeJohn
  • 7,390
  • 6
  • 41
  • 62
17
votes
5 answers

What determines when a class object is destroyed in PHP?

Let's say that we have class CFoo. In the following example when is CFoo::__destruct() called? function MyPHPFunc() { $foo = new CFoo(); . . . // When/where/how does $foo get destroyed/deleted? } In this example would the destructor be…
Jim Fell
  • 13,750
  • 36
  • 127
  • 202
17
votes
3 answers

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

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…
ali
  • 10,927
  • 20
  • 89
  • 138
17
votes
2 answers

Different ways of constructing an object in C++

I want to construct an object in the stack, using C++. Do you know what is the difference between these two ways of calling the constructor (with and without parenthesis): a) MyClass object ; b) MyClass object() ; I am using MFC and when…
lurks
  • 2,576
  • 4
  • 30
  • 39
16
votes
1 answer

Confused: instance creation of c# class in c++

Assume someClass is a class defined in C# with some method int doSomething(void), and for simplicity, providing a constructor taking no arguments. Then, in C#, instances have to be created on the gc heap: someClass c; // legit, but…
Thomas
  • 1,160
  • 3
  • 16
  • 34
16
votes
11 answers

How do I reinitialize or reset the properties of a class?

I've created a class with properties that have default values. At some point in the object's lifetime, I'd like to "reset" the object's properties back to what they were when the object was instantiated. For example, let's say this was the…
Dylan Bennett
  • 1,615
  • 3
  • 17
  • 20
16
votes
6 answers

Pattern for lazy thread-safe singleton instantiation in java

the lazy thread-safe singleton instantion is kinda not easy to understand to every coder, so i wanted to create a class in our enterprise framework that would do the job. What do you think about it? Do you see something bad about it? Is there…
Igor Mukhin
  • 15,014
  • 18
  • 52
  • 61
16
votes
6 answers

Instantiate Java Abstract class?

Relatively new Java programmer and I've been taught that you can't create an instance of an abstract class. I've also done a little research and I learned that in most cases when it appears an abstract class is being created, it is actually an…
Ausome
  • 203
  • 1
  • 6
16
votes
2 answers

no enclosing instance of type... in scope

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…
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
16
votes
6 answers

PHP: How to instantiate a class with arguments from within another class

I am in a situations where i need to instantiate a class with arguments from within an instance of another class. Here is the prototype: //test.php class test { function __construct($a, $b, $c) { echo $a . '
'; echo $b…
Sarfraz
  • 377,238
  • 77
  • 533
  • 578
15
votes
2 answers

class template instantiation

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…
Alcott
  • 17,905
  • 32
  • 116
  • 173
15
votes
4 answers

Why does the compiler try to instantiate a template that I don't actually instantiate anywhere?

Updated below. The following is the entire code I have in my main.cpp: template struct other_traits; template struct some_traits{ typedef decltype(&T::operator()) Fty; typedef typename other_traits::type type; }; int…
Xeo
  • 129,499
  • 52
  • 291
  • 397