redeclaration

Redefinition inconsistency in clang between struct and int

大城市里の小女人 提交于 2019-12-22 11:30:52
问题 The following program gives no error when compiling with clang: namespace X { struct i {}; } namespace Y { using X::i; struct i {}; } int main() {} Let's use int instead of struct, then we get: namespace X { int i; } namespace Y { using X::i; int i; } int main() {} This program gives a redefinition error when compiling with clang. The only difference between the programs is the kind of entity used (struct or int), but one compiles without errors and the other gives a redefinition error. Does

C++ inline functions and redeclarations

五迷三道 提交于 2019-12-11 19:47:59
问题 First of all, sorry for my English. Since GCC totally ignores inline specifiers, it's a little difficult for me to know when a funcion has been marked inline by me or not. What I'm trying to understand is, when you have some redeclarations of a same function (in a same translation unit or in different ones), when or under which circunstances your function is marked inline or not (irrespective of what will the compiler make with your hint). For example: inline void print(); void print(); or:

C++ redeclaration inconsistency/interestingness

♀尐吖头ヾ 提交于 2019-12-11 14:49:17
问题 I was answering this question when I thought of this example: #include <iostream> void func(int i); void func(); int main (){ func(); return 0; } void func(){} In the above example, the code compiles fine. However, in the below example, the code does not compile correctly: #include <iostream> void func(); int func(); int main (){ func(); return 0; } void func(){} This is the error that occurs when this code is compiled (in clang++): file.cpp:4:5: error: functions that differ only in their

redeclaration of instance and static function

江枫思渺然 提交于 2019-12-07 12:51:37
问题 class me { private $name; public function __construct($name) { $this->name = $name; } public function work() { return "You are working as ". $this->name; } public static function work() { return "You are working anonymously"; } } $new = new me(); me::work(); Fatal error: Cannot redeclare me::work() the question is, why php does not allow redeclaration like this. Is there any workaround ? 回答1: There is actually a workaround for this using magic method creation, although I most likely would

Readonly public property redeclared as readwrite in private interface.. understanding a bit more

∥☆過路亽.° 提交于 2019-12-06 09:12:09
问题 I've read the Property redeclaration chapter in The Objective-C Programming Language document and I'd like if some of you can clarify me the following property redeclaration: // MyObject.h public header file @interface MyObject : NSObject { NSString *language; } @property (readonly, copy) NSString *language; @end // MyObject.m private implementation file @interface MyObject () @property (readwrite, copy) NSString *language; @end @implementation MyObject @synthesize language; @end I just want

Redefinition inconsistency in clang between struct and int

﹥>﹥吖頭↗ 提交于 2019-12-06 01:27:01
The following program gives no error when compiling with clang: namespace X { struct i {}; } namespace Y { using X::i; struct i {}; } int main() {} Let's use int instead of struct, then we get: namespace X { int i; } namespace Y { using X::i; int i; } int main() {} This program gives a redefinition error when compiling with clang. The only difference between the programs is the kind of entity used (struct or int), but one compiles without errors and the other gives a redefinition error. Does this indicate a bug in clang? Maybe the standard is ambiguous what a redefinition is when it comes to

Swift 1.2 redeclares Objective-C method

依然范特西╮ 提交于 2019-12-05 16:50:25
问题 I just updated from swift 1.1 to swift 1.2 and get compiler Error: Method 'setVacation' redeclares Objective-C method 'setVacation:' Here some code: var vacation : Vacation? func setVacation(_vacation : Vacation) {...} But I need call setVacation Is any suggestions how fix this? 回答1: This is cause by the change stated in Xcode 6.3beta release notes: Swift now detects discrepancies between overloading and overriding in the Swift type system and the effective behavior seen via the Objective-C

Swift 1.2 redeclares Objective-C method

て烟熏妆下的殇ゞ 提交于 2019-12-04 01:58:55
I just updated from swift 1.1 to swift 1.2 and get compiler Error: Method 'setVacation' redeclares Objective-C method 'setVacation:' Here some code: var vacation : Vacation? func setVacation(_vacation : Vacation) {...} But I need call setVacation Is any suggestions how fix this? This is cause by the change stated in Xcode 6.3beta release notes: Swift now detects discrepancies between overloading and overriding in the Swift type system and the effective behavior seen via the Objective-C runtime. (18391046, 18383574) For example, the following conflict between the Objective-C setter for

How solve compiler enum redeclaration conflict

冷暖自知 提交于 2019-11-29 12:37:54
问题 Consider the following C++ enumerations: enum Identity { UNKNOWN = 1, CHECKED = 2, UNCHECKED = 3 }; enum Status { UNKNOWN = 0, PENDING = 1, APPROVED = 2, UNAPPROVED = 3 }; The Compiler conflicted the both UNKNOWN items and threw this error: error: redeclaration of 'UNKNOWN' I am able to solve this error changing one of the UNKNOWN to UNKNOWN_a , but I would like to do not change the names. How can I solve this conflict without changing the enum items name? 回答1: You can use scoped enumerations

Is there any purpose to redeclaring JavaScript variables?

你离开我真会死。 提交于 2019-11-28 13:37:10
I am new to JavaScript. <html> <body> <script type="text/javascript"> var x=5; document.write(x); document.write("<br />"); var x; document.write(x); </script> </body> </html> Result is: 5 5 When x is declared the second time it should be undefined, but it keeps the previous value. Please explain whether this redeclaration has any special purpose. You aren't really re-declaring the variable. The variable statement in JavaScript, is subject to hoisting, that means that they are evaluated at parse-time and later in runtime the assignments are made. Your code at the end of the parse phase, before