instantiation

How does the Objective-C runtime instantiate the root metaclass and other class descriptions?

I'm trying to implement a basic object-oriented ANSI C runtime and using Objective-C as a guide. They're seems to be three parts. A Class Description, Class Interface, and Class Implementation. In order for the Class Interface to be instantiated, the familiar method of using the Class object to instantiate one's object can only happen i...

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

hello, 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)Functioni...

`new function()` with lower case "f" in JavaScript

My colleague has been using "new function()" with a lower case "f" to define new objects in JavaScript. It seems to work well in all major browsers and it also seems to be fairly effective at hiding private variables. Here's an example: var someObj = new function () { var inner = 'some value'; this.foo = 'blah'; ...

How to instantiate a Socket class in Java?

I know that the Socket class can be instantiated in this way (as an example): new Socket("taranis", 7); where "taranis" is the name of the server in a local network. In this respect I have two questions: 1. If my computers do not form a local network but are connected to the Internet, can I use the IP addresses of computers to instan...

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 to ways of calling the constructor (with and without parenthesis): a) MyClass object ; b) MyClass object() ; I am using MFC and when constructing the global variable for the main app, if I use the latter way, I get an exception, I...

What is the difference between a static variable in C++ vs. C#?

Do static variables have the same or similar functionality in C# as they do in C++? Edit: With C++ you can use static variables in many different contexts - such as: 1) Global variables, 2) Local function variables, 3) Class members - Would similar usages in C# behave similar to that of C++? ...

Objective C: warning on overriding init

I have a class 'DOInstance' which I inherit later on. Here's its declaration: @interface DOInstance : NSObject { } - (DOInstance *) initWithSynckey:(NSString *)_synckey; @end Then I have a subclass of DOInstance: @interface Workflow_Workitem_Header_1px: DOInstance { } //- (Workflow_Workitem_Header_1px *) initWithSynckey:(NSString ...

Can I use methods of a class without instantiating this class?

I have a class with several methods and there is no constructor among these methods. So, I am wondering if it is possible to call a method of a class without a creation of an instance of the class. For example, I can do something like that: NameOfClass.doMethod(x1,x2,...,xn) In general I do not see why it should be impossible. I jus...

Template mutual dependence

Hello, this code: template <class tB> struct A{ typedef float atype; typedef typename tB::btype typeB; }; template <class tA> struct B{ typedef float btype; typedef typename tA::atype typeA; }; struct MyB; struct MyA: public A<MyB>{}; struct MyB: public B<MyA>{}; int main(int argc, char *argv[]) { } does not compile because ...

abstract class NumberFormat - very confused about getInstance()

Hi, I'm new to Java and I have a beginner question: NumberFormat is an abstract class and so I assume I can't make an instance of it. But there is a public static (factory?) method getInstance() that allow me to do NumberFormat nf = NumberFormat.getInstance(); I'm quite confuse. I'll be glad if someone could give me hints on: ...

`return value' from Constructor Exception in Java?

Take a look that the following code snippet: A a = null try { a = new A(); } finally { a.foo(); // What happens at this point? } Suppose A's constructor throws a runtime exception. At the marked line, am I always guaranteed to get a NullPointerException, or foo() will get invoked on a half constructed instance? ...

Unresolved externals with explicit template instantiations. What is the declaration syntax?

Here's some simplified code to demonstrate the problem I have. I have a template function for which I only wish to compile certain fixed instantiations. The function declarations are: // *** template.h *** int square (int x); double square (double x); The definitions are: // *** template.cpp *** #include "template.h" // (template ...

Sending string from class to Form1

Although there are some similar questions I’m having difficulties finding an answer on how to receive data in my form from a class. I have been trying to read about instantiation and its actually one of the few things that does make sense to me :) but if I were to instantiate my form, would I not have two form objects? To simplify th...

OOP - Handling Automated Instances of a Class - PHP

This is a topic that, as a beginner to PHP and programming, sort of perplexes me. I'm building a stockmarket website and want users to add their own stocks. I can clearly see the benefit of having each stock be a class instance with all the methods of a class. What I am stumped on is the best way to give that instance a name when I ins...

java dynamic memory allocation?

Why is an object initialization using the "new" keyword called dynamic memory allocation, since compile time itself we know the memory needed for that object. Also please explain what happens when you do ClassA object = new ClassA(); in heap and stack . ...

Simple vector program error

Hi iam new to c++ and iam trying out this vector program and i am getting the following error: error: conversion from test*' to non-scalar typetest' requested| Here is the code #include <iostream> #include <fstream> #include <vector> #include <string> using namespace std; class test{ string s; vector <string> v; public: ...

C#: Dynamically instantiate different classes in the same statement?

Here is a simplified version of what I'm trying to do: Without having multiple if..else clauses and switch blocks, can I mimic the behavior of Javascript's eval() shudder to instantiate a class in C#? // Determine report orientation -- Portrait or Landscape // There are 2 differently styled reports (beyond paper orientation) string re...

.NET object creation and generations

Is there a way to tell the .NET to allocate a new object in generation 2 heap. I have a problem where I need to allocate approximately 200 MB of objects, do something with them, and throw them away. What happens here is that all the data gets copied two times (from gen0 to gen1 and then from gen1 to gen2). ...

Is it possible to restrict instantiation of an object to only one other (parent) object in VB.NET?

VB 2008 .NET 3.5 Suppose we have two classes, Order and OrderItem, that represent some type of online ordering system. OrderItem represents a single line item in an Order. One Order can contain multiple OrderItems, in the form of a List(of OrderItem). Public Class Order Public Property MyOrderItems() as List(of OrderItem) End...

How can a class's memory-allocated address be determined from within the contructor?

Is it possible to get the memory-allocated address of a newly instantiated class from within that class's constructor during execution of said constructor? I am developing a linked list wherein multiple classes have multiple pointers to like classes. Each time a new class instantiates, it needs to check its parent's list to make sure i...