declaration

unmanaged var as member of managed class c++

让人想犯罪 __ 提交于 2019-11-28 08:09:36
问题 I'm novice in .net c++ and trying to create class looking like: public ref class Klient { public: Klient(){} // zmienne static DWORD klienty[41][2]; static int i = 1; static DWORD* pid; static HANDLE* handle; //funkcje }; but MSV says that: error C4368: cannot define 'klienty' as a member of managed 'Klient': mixed types are not supported What's wrong with this code? 回答1: You can have .NET basic data types as members of your managed class (static int i), or pointers to anything unmanaged

Is Type(::x); valid?

我的未来我决定 提交于 2019-11-28 07:26:45
While discussing the Type(identifier); syntax and how it's a declaration, I came across Type(::x); not working with Clang. I would expect that given a global variable x , it would treat ::x as an expression ( ::x + 2 works) and cast ::x to Type . However, it gives a compiler error. Here is a short example : int x; int main() { int(::x); //does not compile int(::x + 2); //compiles } The compiler error given by Clang 3.5 is: error: definition or redeclaration of 'x' cannot name the global scope GCC 4.9.0, however, compiles this just fine. Is this code valid or not? As far as I can tell this is

Grammar of a C++ Translation Unit

◇◆丶佛笑我妖孽 提交于 2019-11-28 07:24:00
问题 My understanding, for a long time now, was that a C++ translation unit , after the preprocessor has run, is a sequence of declarations (let me remind that any definition is also a declaration). Many people have argued with this statement but no one has ever given a counterexample. But I myself found this example which troubles me: int x; //declaration ; // ??? EMPTY DECLARATION? int main() //dec { //la } //ration This compiles fine with MSVC and online comeau. I know the standard defines an

Java, What is the difference between assigning null to object and just declaration

♀尐吖头ヾ 提交于 2019-11-28 07:21:27
What is difference between : Object o = null ; and Object o; (just declaration) Can anyone please answer me? PermGenError It depends on the scope where you declare the variable. For instance, local variables don't have default values in which case you will have to assign null manually, where as in case of instance variables assigning null is redundant since instance variables get default values. public class Test { Object propertyObj1; Object propertyObj2 = null; // assigning null is redundant here as instance vars get default values public void method() { Object localVariableObj1; Object

Ambiguous function declaration in Javascript

孤者浪人 提交于 2019-11-28 07:13:20
问题 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 a function object If we declare the function and redeclare that afterwards: function say() { alert("speak"); } say(); function say() { alert("say"); } I got "say" instead of

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

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 06:36:24
问题 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. 回答1: You can achieve that by implementing getter and setters in the delegate class. In delegate .h file Include UIApplication delegate @interface DevAppDelegate : NSObject <UIApplicationDelegate> NSString * currentTitle; - (void) setCurrentTitle:(NSString *) currentTitle; - (NSString *) getCurrentTitle; In Delegate

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

我与影子孤独终老i 提交于 2019-11-28 06:33:20
问题 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

Declare C89 local variables in the beginning of the scope?

╄→尐↘猪︶ㄣ 提交于 2019-11-28 06:00:16
问题 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

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

淺唱寂寞╮ 提交于 2019-11-28 04:34:58
问题 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

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

痴心易碎 提交于 2019-11-28 03:15:20
问题 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 file. What are the advantages & disadvantages of this approach? 回答1: Historically this was to help the compiler. You had to give it the list of names before it