Let's say I have a struct defined as:
typedef
struct number{
int areaCode;
int prefix;
int suffix;
} PhoneNumber;
When I create an instance of this struct, if I use the following syntax:
PhoneNumber homePhone = {858, 555, 1234};
...which constructor is it calling? The default constructor, or the copy constructor, or non...
Hi, I have a custom class defined in Actionscript and I want to make an instance of it in the main document of Flash application. However, after calling the constructor with one argument, Flash gives me this error:
Error #1063: Argument count mismatch on coa.application::MenuItem(). Expected 1, got 0.
This is my class:
public class M...
Hello,
I seem to be having a very frustrating time with an inherited class calling an explicit superclass constructor. I just can't seem to get the syntax right!
All the examples I have seen on the matter so far do not separate out the header and in-line class definition (using {}'s) from forward-declarations with a header file, so I'...
In the code below I recieve the compile error "Error Too many arguments to 'Public Sub New()'" on the "Dim TestChild As ChildClass = New ChildClass("c")". I do not recieve it on "TestChild.Method1()" even though they are both on the base class I am inheriting from.
Public Class BaseClass
Public ReadOnly Text As String
Public Sub...
How can I create an instance of an object using a class reference, and
ensure that the constructor is executed?
In this code example, the constructor of TMyClass will not be called:
type
TMyClass = class(TObject)
MyStrings: TStrings;
constructor Create; virtual;
end;
constructor TMyClass.Create;
begin
MyStrings := ...
Hi i've got the following code in a ViewController.h:
#import <UIKit/UIKit.h>
@interface CalcViewController : UIViewController {
NSNumber* result;
NSString* input;
//NSString* input = @"";
IBOutlet UITextField* display;
}
@property (retain) NSNumber* result;
@property (retain) NSString* input;
@property (nonatomic, re...
Compiler Error
Keyword 'this' is not available in the current context
delegate void CallBack(int i);
class A
{
public A(CallBack cb) { }
}
class B : A
{
public B() : base(new CallBack(this.f)){}
private void f(int i) { }
}
Why is this error ?
As a solution I thought of providing a parameterless protected ctor ...
So I've been brushing up on my Java skills as of late and have found a few bits of functionality that I didn't know about previously. Static and Instance Initializers are two such techniques.
My question is when would one use an initializer instead of including the code in a constructor? I've thought of a couple obvious possibilities:
...
First things first, here is a little snippet code to help explain my problem:
<?php
class foo {
public $title;
__construct{
echo "<html>\n";
echo "<head>\n";
echo "<title>".$this->title."</title>\n";
echo "</head>\n";
echo "<body>\n";
}
/**
*
* I get $title from index....
Im having a debate with a co-worker about throwing exceptions from constructors, and thought I would like some feedback.
Is it ok to throw exceptions from constructors, form a design point of view?
Lets say I'm wrapping a posix mutex in a class, it would look something like this.
class Mutex {
public:
Mutex() {
if(pthread_mutex_...
Well, I'm trying to reuse a portion of C# code. It's an abstract class with UDP server, which can be seen here:
http://clutch-inc.com/blog/?p=4
I've created a derived class like this:
public class TheServer : UDPServer
{
protected override void PacketReceived(UDPPacketBuffer buffer)
{
}
protected o...
So basically I understand this ...
class User
{
function __construct($id) {}
}
$u = new User(); // PHP would NOT allow this
I want to be able to do a user look up with any of the following parameters, but at least one is required, while keeping the default error handling PHP provides if no parameter is passed ...
class User
{
...
Why does constructor ORDER matter in VB.Net? I am building a .Net type library which is meant to wrap an underlying COM library completely so that the consumers of the API can pretend to use a nice .Net library with .Net collections and whatnot instead of a COM library.
Currently most of my classes are just 1 to 1 wrappers built using R...
Hi
I know we can explicitly call the constructor of a class in C++ using scope resolution operator i.e. className::className()
I was wondering where exactly would I need to make such a call.
cheers
...
I have a class with 2 constructors:
public class Lens
{
public Lens(string parameter1)
{
//blabla
}
public Lens(string parameter1, string parameter2)
{
// want to call constructor with 1 param here..
}
}
I want to call the first constructor from the 2nd one. Is this possible in C#?
...
I have been reviewing some code that looks like this:
class A; // defined somewhere else, has both default constructor and A(int _int) defined
class B
{
public:
B(); // empty
A a;
};
int main()
{
B* b;
b = new B();
b->a(myInt); // here, calling the A(int _int) constructor,
//but default constructor should al...
My webservice constructor is getting called each time that I call a webmethod. This is causing some problems with some new functionality that I am adding and I cannot figure out what I am doing wrong to cause this. The only place that I am newing the webservice is in global.asax.cs's Application_Start, but if I remove the code to new the...
Following are the two approaches:
constructor with all the class properties
Pros: I have to put an exact number of types of parameters so if I make an error the compiler warns me (by the way, is there a way to prevent the problem of having erroneously switched two Integer on the parameter list?)
Cons: if I have lots of properties t...
So I have this piece of code and out of convenience I want the default parameter for its constructor be of the int kind and 0. (I have more parameters in a class of my project and one of them is optional and I don't want to write the constructor twice because its big)
class mama{
public:
template<typename x> mama(x i=int(0)){}
}...
C# noob question...
I'm taking a few arguments in a class constructor to initialize some private variables. What should I do when the data passed in is not what I expect (wrong string length, numbers out of expected range, nonexisting path, stuff like that..)? Throw an exception? Add "everything went ok" flag?
how is it usually done?
...