declaration

vb6 to vb.net declaration

How do I declare "as any" in VB.NET, or what is the equivalent? ...

The best way to invoke methods in Python class declarations?

Say I am declaring a class C and a few of the declarations are very similar. I'd like to use a function f to reduce code repetition for these declarations. It's possible to just declare and use f as usual: >>> class C(object): ... def f(num): ... return '<' + str(num) + '>' ... v = f(9) ... w = f(42) ... >>> C.v...

Declarations, definitions, initializations in C, C++, C#, Java and Python

What do the terms mean in each of the above languages? Why do the languages differ (wherever they do, if at all they do) in this respect? ...

C++ array size dependent on function parameter causes compile errors

I have a simple function in which an array is declared with size depending on the parameter which is int. void f(int n){ char a[n]; }; int main() { return 0; } This piece of code compiles fine on GNU C++, but not on MSVC 2005. I get the following compilation errors: .\main.cpp(4) : error C2057: e...

when to pass a parameter and when to use an instance variable

How do you guys decide between keeping track of something locally and then just passing it in to every method you call on it, or declaring an instance variable and using it in the methods? I tend to prefer instance variables kept in a list at the end of the Class. But as my programs become more and more complicated, this list gets longe...

php: pushing to an array that may or may not exist

I want to create an array with a message. $myArray = array('my message'); But using this code, myArray will get overwritten if it already existed. If I use array_push, it has to already exist. $myArray = array(); // <-- has to be declared first. array_push($myArray, 'my message'); Otherwise, it will bink. Is there a way to make...

Forward Declaration of a Base Class

Hello, I'm trying to create proper header files that don't include much other files. (To keep them clean, to speed up compiling time, ...) I encountered two problems while doing this: 1 - Forward declaratoin on base classes doesn't work. class B; class A : public B { // ... } 2 - Forward declaration on STD classes doesn't work...

Difference between declaring variables before or in loop?

Hi, I have always wondered if, in general, declaring a throw-away variable before a loop, as opposed to repeatedly inside the loop, makes any (performance) difference? A (quite pointless example) in Java: a) declaration before loop: double intermediateResult; for(int i=0;i<1000;i++){ intermediateResult = i; System.out.println...

What does this VB6 variable declaration do?

I just found this in some old code, and I'm not sure what it means. Dim sTemp As String * 1 What is the * 1 at the end? Thanks! ...

C++ Forward Declaration Problem when calling Method

I have a problem which I think is related to forward declarations, but perhaps not. Here is the relevant code: A.h #ifndef A_H_ #define A_H_ #include "B.h" class A { private: B b; public: A() : b(*this) {} void bar() {} }; #endif /*A_H_*/ B.h #ifndef B_H_ #define B_H_ #include "A.h" class A; class B {...

How to declare a function in Cocoa after the function using it?

I'm slowly building my application to a working state. I'm using two functions called setCollection and addToCollection. These functions both accept NSArray as input. I also have a function called add in which I use both of these functions. When I try to compile, Xcode shows an error: 'setCollection' undeclared (first use in this f...

labeling a group of members as private/public in c#

in a c++ class declaration, you can label a group of members as private or public, e.g. private: int x; double y; seems like there's no way to do this in c#. am I wrong? ...

What for should I mark private variables as private if they already are?

Hello. As far as I know, in C# all fields are private for default, if not marked otherwise. class Foo { private string bar; } class Foo { string bar; } I guess these two declarations are equal. So my question is: what for should I mark private variables as private if they already are private? ...

Take an array of any value type as formal parameter

I would like to be able to declare a function as void foo(<any value type>[] data){} in C# 2.0. If I declare it as void foo(ValueType[] data){} it compiles, but then the elements in data[] are treated as though they're derived from object, e.g. I can't say something like fixed (void* pData = data){} I'd like to avoid taking the...

Regex for variable declaration and initialization in c#

I want to write a RegEx to pull out all the variable values and their names from the variable declaration statement. Say i have int i,k = 10,l=0 i want to write a regex something like int\s^,?|(^,?)* but this will also accept k = 10 i.e. (without int preceding it) Basically idea is If string starts with int then get the variable list s...

What is the preferred way to declare a Java array?

Possible Duplicate: Difference between int[] array and int array[] What is the difference between these two declarations of an array of native types in Java? double items[] = new double[10]; double[] items = new double[10]; If they are the same is there any reason to prefer one over the other? ...

default value of a variable at the time of declaration in C# and VB ??

Can anybody tell me what is the default value of a variable at the time of declaration in C# and vb?? ...

undefined C struct forward declaration

Hello, I have a header file port.h, port.c, and my main.c I get the following error: 'ports' uses undefined struct 'port_t' I thought as I have declared the struct in my .h file and having the actual structure in the .c file was ok. I need to have the forward declaration as I want to hide some data in my port.c file. In my port.h I ...

Help with declaring C++ structure, with a float array as one of its members.

I was wondering if anyone could spot what is wrong with my structure declaration and use. At the moment I have a structure and wish to store float array as one of it's members. My code: struct Player{ float x[12]; float y[12]; float red,green,blue; float r_leg, l_leg; int poly[3]; bool up,down; }; I then tried filling the struct: f...

What are the advantages and disadvantages of separating declaration and definition as in C++?

In C++, declaration and definition of functions, variables and constants can be separated like so: function someFunc(); function someFunc() { //Implementation. } In fact, in the definition of classes, this is often the case. A class is usually declared with it's members in a .h file, and these are then defined in a corresponding .C...