问题标签 [redeclaration]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
104 浏览

class - DXE7: "type A = type B" and var x (of type A):= A.create leads to E2010 incompatible type compile error. Why?

A. Short summary of the problem:

The compiler error E2010 incompatible types: 'B' and 'A' is shown, when you instantiate a variable of class B in the following style:

I can avoid that problem by removing the second "type", so the declaration is the standard one:

But in my opinion, the error should not come, even WITH the second "type", because A is not directly used (The second "type" tells the compiler to see both classes as individuals, see http://docwiki.embarcadero.com/RADStudio/Seattle/en/Declaring_Types for details). Can someone explain, because of what reason the error ignores my opinion? (o;

B. Complete history and more complex details:

First of all: The error:

[dcc32 Fehler] gboDHL.pas(165): E2010 Inkompatible Typen: 'Origin' und 'CountryType' (which means "incompatible types" in english),

occurs in the following line of code:

Now here is the background:

I try to communicate with the "new" DHL Geschäftskundenversand API v2.2 which still uses SOAP to create a shipment order. DHL_geschaeftskundenversand_api_2 is the completely generated unit from the integrated delphi xe7 WSDL generator for that service. AShipmentOrder is the instance which represents the top level xml node of the request.

The class "Origin" is implemented/generated this way:

The "property" Origin of AShipmentOrder.Shipment.Shipper.Address is implemented/generated this way:

If it is unclear, let me say, that ´AShipmentOrder.Shipment.Shipper.Address´ is of class NativeAddressType

I'm using Delphi XE7 on Windows 10, 64bit, compiling to 32bit.

The delphi WSDL generator has different problems, which I had to manage before, and it is really not "nice" that in the output the property names are identical to the class names, but that is not changeable, it seems. The class "Origin" is not the only class in that generated unit which is named as the property it belongs to, but the error only occurs, when such a class is implemented as

I tried to find a description of that special declaration variant, but that is quite hard, because the keywords are too often used.

On http://www.delphibasics.co.uk/RTL.asp?Name=Type I found the following explanation:

1.type Name = Existing type   Refers to an existing type, such as string by a new Name.   2.type Name = type Existing type   This has the same effect as above, but ensures that at run time, variables of this type are identified by their new type name, rather than the existing type name.

If I understand that correctly, that means that in my example the class Origin is not identified anymore as CountryType, but as Origin. That should be fine, because the property Origin is declared as to be of class Origin.

While going on to try to understand that problem, I manually renamed The class "Origin" in the generated unit to OriginType (delphi used that postfix "Type" with several other classes in that unit, not clear, why it has not used it with the Origin-Type). After that, I can exclude a name-conflict, because now the error is

[dcc32 Fehler] gboDHL.pas(165): E2010 Inkompatible Typen: 'OriginType' und 'CountryType'

There seems to be no reason because of what that error occurs.

After some hours without some ideas I found this Embarcadero WIKI entry: http://docwiki.embarcadero.com/RADStudio/Seattle/en/Declaring_Types

After reading and thinking about that, I understood, that the "type" in A = type B is not necessary in that case, because there is no need to handle class A in another way than class B, so I removed that manually in the generated unit and now, it works fine.

I also understand, that a special option in the generator was checked to prevent "name conflicts". If this option is not checked, this problem also should be solved (but maybe some others come around (o; ).

Maybe this helps someone to spent more time outside than with a problem like that (o;

But in the end, I do not understand what was the problem here, because all properties were of type "Origin" and later of "OriginType", also this type was created with Origin.Create and later with OriginType.Create. So the "CountryType" was never used, except for the class declaration of "Origin" / "OriginType". In my opinion this should not lead to that problem, but it does.

Can somebody explain that?

Thank you in advance

Kai

0 投票
1 回答
947 浏览

php - 错误 500:PHP 致命错误:无法重新声明 thim_widgets_inits()

我的页面 tolkeuddannelsen.dk 上出现 error500。通过错误日志,我可以确定它在我的主题 function.php 中的第 93-185 行导致了问题。这就是我的虚拟主机所说的:后端致命错误:PHP 致命错误:无法在 /var/www/www 中重新声明 thim_widgets_inits()(之前在 /var/www/www.tolkeuddannelsen.dk/www/functions.php:93 中声明) .tolkeuddannelsen.dk/www/wp-content/themes/elearningwp/functions.php 在第 185 行\n,参考:http: //tolkeuddannelsen.dk/

这些行中的代码如下所示。

谁能帮我解决这个问题?谢谢!

0 投票
2 回答
7295 浏览

ios - Xcode:'ViewController'的无效重新声明

我刚刚完成了我的应用程序,它工作正常,但是在按下文件 - > 复制后突然,我有一条消息说

'ViewController' 的无效重新声明

如果可以的话请帮帮我好吗?谢谢

0 投票
2 回答
275 浏览

c++ - C++ 内联重新声明

考虑以下示例(在同一翻译单元中):

重新声明时会发生什么ff还算inline不算?

我查看了这种情况的标准,但我只在 10.1.6/6 [dcl.inline] 中找到了它的反面:

[...] 如果函数或变量的定义在其第一次声明为内联之前出现在翻译单元中,则该程序格式错误。[...]

我想要标准中的一些参考资料,说明在这种情况下会发生什么。

我看到了这篇文章,但它没有在标准中显示明确的参考。我倾向于相信没有这样的参考。

0 投票
1 回答
123 浏览

c++ - C++ 重新声明不一致/有趣

当我想到这个例子时,我正在回答这个问题:

在上面的例子中,代码编译得很好。但是,在下面的示例中,代码无法正确编译:

这是编译此代码时发生的错误(在 clang++ 中):

我预计两次都会出现这样的错误。

我稍微摆弄了一下代码,出于某种完全奇怪的原因,链接器似乎完全忽略了不正确的声明。现在这允许一些非常奇怪的代码。例如这个头文件是合法的:

为什么?为什么在世界上任何一个都有效?这只是 C++ 标准失败吗?编译器故障?“特征”?实际功能?(顺便说一句,这只是一个问题。)

PS 当我在等待答案时,我将在这里利用这一点在代码中预先添加可能最终会投入生产的功能。

0 投票
1 回答
49 浏览

objective-c - 重新声明的属性无法识别为 getter 的重新声明类型

当我重新声明一个属性(只读-> 读写属性和协议-> 具体类型)时,我遇到了一个问题。在实现中使用 getter 时,我希望 getter 具有重新声明的类型,但它保留了原始类型。

请参阅示例:

Foo.h

Foo.m

测试.h

测试.m

说了这么多,我有两个问题:

  1. 谁能向我解释为什么 foo getter 在实现中访问时不使用重新声明的类型?

  2. 有没有好的解决方案/解决方法

    A.修改Test.h中的接口(不想暴露更多,或者让接口更复杂)

    B. 每当我使用 foo getter 时,它的结果都会被转换(不是很干净的代码)

非常感谢任何帮助,谢谢!


我确实提出了一种可能的解决方法,即声明第二个属性而不是重新声明原始属性,但我认为它不是最干净的,并且肯定会使代码更容易阅读:

Test.m(有解决方法):

0 投票
2 回答
537 浏览

c++ - 如何在 C++ 中重新声明类对象?

我正在对类和构造函数进行试验,并且我正在尝试根据 if 语句之类的内容为类对象选择特定的声明。我写了一个简单的例子,展示了我试图做的事情,但这是行不通的。即使它满足 if 语句,它也会打印第一个声明对象的“id”,如果我没有在 if 语句之前声明它,我会得到错误“a not declared in this scope”的打印。有没有办法重新声明一个类对象,然后通过 if 语句使用它?

0 投票
0 回答
105 浏览

c - C 线程程序:为什么这段代码给了我“重新声明为不同类型的符号”错误?

我正在尝试编写一个客户端程序,该程序将使用多个线程一次从服务器下载多个块的文件。在继续之前,我首先尝试仅使用一个线程成功下载文件,但我不断收到此重新声明错误。我已经声明了一个全局变量索引,并想在一个函数中更新它。

据我所知,我没有在任何一个函数中重新声明索引,我认为在 C 中你可以毫无问题地修改函数中的全局变量。如果这是一些明显的错误或误解,我深表歉意,但任何帮助将不胜感激。

0 投票
1 回答
157 浏览

php - 无法为每个重新声明函数错误

我正在尝试从自定义帖子中提取信息,将其输入 foreach 循环,然后将其回显到重复面板中的函数中。在某些时候,我猜测函数声明正在被重新声明(它不在任何其他文件中,我对此有 100% 的信心),因为我不断收到“无法重新声明 output_member() 先前在同一文件路径中声明的 php 43 ”。

任何帮助表示赞赏。

0 投票
0 回答
1556 浏览

c++ - 如何修复重新声明错误:无法在 C++ 中重新声明类成员

试图重载类的成员函数,发生重新声明错误。

在类声明中,甚至 Qt 也揭示了一个问题:

此消息是为以下代码中标记为“overload2”的类提供的:

编译失败,抱怨重载。

如果删除“Overload 1/2”成员函数之一,则编译工作。

为什么这些函数不能一起重载?