declaration

Where various variable and method types should be placed in a header

给你一囗甜甜゛ 提交于 2019-11-29 12:51:14
I've noticed that I get compilation errors if I place certain declarations in certain places in my header file. I've put comments into the code as to where I think certain things go; are they correct? @interface Level : CCNode { //Instance variables? PlayBackgroundLayer* playBGLayer; PlayUILayer* playUILayer; PlayElementLayer* playElementLayer; } //Static methods? +(void) InitLevel: (int) levelNumber; +(Level*) GetCurrentLevel; //Property declarations for instance variables? @property (nonatomic, retain) PlayBackgroundLayer* playBGLayer; @end //Static variables? Level* currentLevel;

Declaring Variables Memory Leaks

青春壹個敷衍的年華 提交于 2019-11-29 12:28:33
I am wondering what would be the most correct way to deal with memory when using VBScript. Should declare all variables right before I use them? The beginning of the program? I understand global vs local, however in my script all variables are local. I know that memory leaks will never be a problem when writing in VBScript 99.9% of the time, but I am also curious as to the 'best' way to clear and release memory within a script. By 'best' I mean, the timing of clearing variables/objects (right after you are done using them vs the end of the script), etc. An example: Dim fso: Set fso =

Declare C89 local variables in the beginning of the scope?

时光总嘲笑我的痴心妄想 提交于 2019-11-29 12:21:52
I was trying to do this in ANSI C: include <stdio.h> int main() { printf("%d", 22); int j = 0; return 0; } This does not work in Microsoft Visual C++ 2010 (in an ANSI C project). You get an error: error C2143: syntax error : missing ';' before 'type' This does work: include <stdio.h> int main() { int j = 0; printf("%d", 22); return 0; } Now I read at many places that you have to declare variables in the beginning of the code block the variables exist in. Is this generally true for ANSI C89? I found a lot of forums where people give this advice, but I did not see it written in any 'official'

Redeclaration of a variable in a for-loop in C++

老子叫甜甜 提交于 2019-11-29 11:45:46
问题 When trying to compile the following (simplified) code for multiple platforms, I found that it was failing on some, namely IBM's xlC_r. Further investigation has found that it also fails on comeau and clang. It compiles successfully with g++ and Solaris's CC. Here is the code: int main() { int a1[1]; bool a2[1]; for (int *it = a1, *end = a1+1; it != end; ++it) { //... bool *jt = a2, *end = a2+1; //... } } xlC_r error: "main.cpp", line 8.25: 1540-0400 (S) "end" has a conflicting declaration.

Figuring out C Declarations like: double (*b)[n]

放肆的年华 提交于 2019-11-29 11:41:29
问题 I'm trying to figure out some C declarations. What is the meaning of these C declarations? double (*b)[n]; double (*c[n])(); double (*d())[n]; 回答1: double (*b)[n]; b is a pointer to an array of n doubles double (*c[n])(); c is an array of n pointers to functions taking unspecified number of arguments and returning double double (*d())[n]; d is a function taking unspecified number of arguments and returning a pointer to an array of n doubles In general, in order to parse these kind of

Global qualification in a class declarations class-head

谁都会走 提交于 2019-11-29 11:36:44
We found something similar to the following (don't ask ...): namespace N { struct A { struct B; }; } struct A { struct B; }; using namespace N; struct ::A::B {}; // <- point of interest Interestingly, this compiles fine with VS2005, icc 11.1 and Comeau (online), but fails with GCC: global qualification of class name is invalid before '{' token From C++03, Annex A, it seems to me like GCC is right: the class-head can consist of nested-name-specifier and identifier nested-name-specifier can't begin with a global qualification ( :: ) obviously, neither can identifier ... or am i overlooking

Automatically separate class definitions from declarations?

◇◆丶佛笑我妖孽 提交于 2019-11-29 11:35:33
I am using a library that consists almost entirely of templated classes and functions in header files , like this: // foo.h template<class T> class Foo { Foo(){} void computeXYZ() { /* heavy code */ } }; template<class T> void processFoo(const Foo<T>& foo) { /* more heavy code */ } Now this is bad because compile times are unbearable whenever I include one of those header files (and actually I include many of them in each of my compilation units). Since as a template parameter I only use one or two types anyway I am planning to create, for each library header file, a file that contains only

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

元气小坏坏 提交于 2019-11-29 11:03:52
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()); return 0; } double f(int a) { return 1; } Visual C++ 2008 compiler show the following error: Error 2 error C2371: 'f' : redefinition; different basic types d:\temp\projects\function1\function1\1.c 8 function1 Can anybody explain this strange behavior? Both the programs are wrong. Without a prototype in

Generics wildcard instantiation

走远了吗. 提交于 2019-11-29 10:30:58
I was reviewing someone else's code the other day and I came across a line that raised some concern. To simplify, say I have a generic Class A and an abstract Class B. Is the following instantiation allowed and if so, why? Object obj = new A<? extends B>(); I personally have never seen an instantiation like the above, although a declaration such as A<? extends B> obj = null; would certainly hold. I've always used the wildcard in generics to declare method parameters, so I may just not have the experience. Actually new A<? extends B>() does not compile. It has been consistently illegal since

Hide instance variable from header file in Objective C

给你一囗甜甜゛ 提交于 2019-11-29 10:06:57
问题 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 its corresponding ivar inside the interface's {}, the compiler will give me an error. Ultimately, I want to hide the internal structure of my class inside the .a, and