declaration

Where to declare/define class scope constants in C++?

I'm curious about the benefits/detriments of different constant declaration and definition options in C++. For the longest time, I've just been declaring them at the top of the header file before the class definition: //.h const int MyConst = 10; const string MyStrConst = "String"; class MyClass { ... }; While this pollutes the globa...

Ambiguous function declaration in Javascript

I am new to Javascript and got confused by how the function declaration works. I made some test on that and got some interesting results: say(); function say() { alert("say"); } The forward-declaration worked and popup "say" On the opposite say(); say = function() { alert("say"); } did not work, although it also declared...

Hide instance variable from header file in Objective C

I came across a library written in Objective C (I only have the header file and the .a binary). In the header file, it is like this: @interface MyClass : MySuperClass { //nothing here } @property (nonatomic, retain) MyObject anObject; - (void)someMethod; How can I achieve the same thing? If I try to declare a property without i...

can I declare an array where one of the array elements is undeclared variable? (ruby)

#input_from_the_net = "" my_array = [ ["Header name" , input_from_the_net] ] input_from_the_net = "a value scraped from the net" puts "#{my_array[0][0]} is #{my_array[0][1]}" EDIT: I use the variable input_from_the_net later on in the loop and assign its value into a hash. That hash is then stored inside another hash. If I use inpu...

Declare in C == define in C++ ?

Possible Duplicate: What is the difference between a definition and a declaration? Is it correct that to declare in C is equal to define in C++? int a; /* to declare variabel a in C */ int b = 2; /* to declare and initialize in C */ int c; // to define in C++ int d = 4; // to define and initialize in C++ ...

In java, why I can declare a varaible named "a" but not "1" ?

Everything is fine when I declare String a; but it says Syntax error on token "1", invalid VariableDeclaratorId when I do this String 1; I guess it must be very trivial but I don't get it. ...

How to define /declare a class intance in a .hpp / .cpp file?

Hello, I'm pretty sure that this question is very noob but I'm not used to C++. I have a .hpp for class definition and a .cpp for class implementation. I have some private instances on the class, for example: class Test { Test(void); private: SomeClass anInstance; }; To create the instance and call the constructor do...

Can a union be initialized in the declaration?

For example, say we have a union typedef union { unsigned long U32; float f; }U_U32_F; When a variable of this union type is declared, is there a way to set an initial value? U_U32_F u = 0xffffffff; // Does not work...is there a correct syntax for this? ...

hide function template, declare specializations

This is a followup to http://stackoverflow.com/questions/2050900/c-templates-prevent-instantiation-of-base-template I use templates to achieve function overloading without the mess of implicit type conversions: declare the function template, define desired specializations (overloads). all is well except wrong code does not produce erro...

How to Access String Variable in One View Controller to Another view Controller

Hi, I am new to iphone development, Now i want to access the string variable in all the view controller, but i know to declare the variables in delegate method, but i cant access it, please help me out. Mainviewcontroller-->Viewcontroller1_-->viewcontroller2-->viewcontroller3-->subwebview. i have created one main view controller and t...

Is there any difference between "Object[] x" and "Object x[]" ?

I was updating a legacy ode base in Java and I found a line like this: Object arg[] = { new Integer(20), new Integer(22) }; That line catch my attention because I am used to this kind of code: Object[] arg = { new Integer(20), new Integer(22) }; The content of the array isn't important here. I'm curious about the brackets next to t...

Objective-C: How Can I Access String Variable As a Global?

Hi, I am new to iPhone development. I want to access a string variable in all the class methods, and I want to access that string globally. How can I do this? Please help me out. ...

When do you use * in variable definitions (in Objective-C)?

Hi there, I'm still getting confused by Objective-C. Sometimes you declare a variable like so: NSRect rect; And sometimes like so: NSValue *value; I never know when to add the *, so far I always looked it up in Apple's documentation. I know the difference is between a value and a pointer to an object. But are there any hard and ...

type of int * (*) (int * , int * (*)())

hi , int * (*) (int * , int * (*)()) I'd like to know what type is it ? , can someone give an example of a declaration using this type. any help would be great. thanks. ...

Is there something in PHP similar to Option Explicit in VB

I am doing a big project in PHP. In PHP you do not need to declare variables. This is causing a lot of problems for me. In Visual Basic 6, the Option Explicit statement makes it mandatory to declare variables. Is something similar available in PHP? ...

The behavior of a C compiler with old-styled functions without prototypes

When my program consists of two files: main.c #include <stdio.h> int main(void) { printf("%lf\n",f()); return 0; } func.c double f(int a) { return 1; } compiler do not show any errors. When my program consists of only one file: main.c #include <stdio.h> int main(void) { printf("%lf\n",f()); retur...

any open source IDE with the possibility to go the declaration of a function, a variable..?

Hi, any open source IDE with the possibility to go the declaration of a function, a variable, a class... presing a key(s)?? Apart from Netbeans and Eclipse. Regards Javi ...

Is there a difference between only <NSXMLParserDelegate>, only setDelegate method, or the use of both of them ?

Hey, I noticed that when I do this : [myParser setDelegate:self]; it works :D (even if I didn't add the code in the header file ... you know, the <delegateStuff, delegateOtherStuff> in the interface declaration) When are you supposed to modify the header file to make your delegate work ? Is the setDelegate method enough to ma...

ANSI-C grammar - array declarations like [*] et alii

The ANSI C grammar from -link- give me the following rules for array declarations: (1) | direct_declarator '[' type_qualifier_list assignment_expression ']' (2) | direct_declarator '[' type_qualifier_list ']' (3) | direct_declarator '[' assignment_expression ']' (4) | direct_declarator '[' STATIC type_qualifier_list assignment_expre...

Where can I legally declare a variable in C99?

When I was first introduced to C I was told to always declare my variables at the top of the function. Now that I have a strong grasp of the language I am focusing my efforts on coding style, particularly limiting the scope of my variables. I have read this SO question on the benefits to limiting the scope and I came across an interesti...