在我关于ploymorphism的一篇教程幻灯片中,我看到这段代码有几条评论:
discountVariable = //will produce
(DiscountSale)saleVariable;//run-time error
discountVariable = saleVariable //will produce
//compiler error
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,它在第一个演示语句中表示它将产生运行时错误,而在另一个演示语句中它表示它将产生编译器错误.
是什么造成这些错误?以及他们彼此之间的差异?
在安装CocoaLumberjack'日志压缩器类后,我一直在遇到这种恼人的行为:Xcode抱怨说有很多未声明的标识符,并且给了我很多错误(不是警告,而是带有红色图标的错误).
问题是我可以编译和运行我的iPad应用程序,但Xcode不会做任何自动完成.我尝试清理构建文件夹(Product> option+ Clean),还删除了派生数据.我也重新启动无济于事.
你可以想象这是一种痛苦的工作.我确实在之前版本的Xcode上发生过这种行为; 它与我的预编译头文件中的东西有关,但使用上面的解决方案总能修复它.我目前正在使用Xcode 4.4(4F250).
我得到的示例错误:
Semantic Error: use of undeclared identifier 'DDTTYLogger'
上面发生的事情甚至发生在我自己编写的类中,并且自安装CocoaLumberjack压缩器类以来没有改变.
什么是未声明的标识符错误?什么是常见原因以及如何解决它们?
示例错误文本:
error C2065: 'cout' : undeclared identifier'cout' undeclared (first use in this function)我刚刚在我的项目中添加了一个Watch应用程序并尝试:
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
let res = WKInterfaceController.openParentApplication(["key" : "value"]) { (replyInfo, error) -> Void in
print("replyInfo : \(replyInfo) + error \(error)")
}
print(res) // true here
}
Run Code Online (Sandbox Code Playgroud)
在我的AppDelegate中,我写道:
func application(application: UIApplication, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]?, reply: ([NSObject : AnyObject]?) -> Void) {
reply(["replyKey" : "replyValue"]);
}
Run Code Online (Sandbox Code Playgroud)
当我启动Watch应用程序时,我只有:
replyInfo:[:] + error可选(错误域= FBSOpenApplicationErrorDomain Code = 3"操作无法完成.(FBSOpenApplicationErrorDomain eor 3.)")
是由于模拟器?你知道做错了什么吗?
谢谢 !
如果在C++中定义了一个新变量,则可以在初始化表达式中使用该变量的名称,例如:
int x = sizeof(x);
Run Code Online (Sandbox Code Playgroud)
那么函数参数的默认值又如何呢?是否允许通过名称引用参数?例如:
void f(int y = sizeof(y)) {}
Run Code Online (Sandbox Code Playgroud)
该函数在 Clang 中被接受,但在 GCC 中被拒绝,并出现错误:
'y' was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
演示: https: //gcc.godbolt.org/z/YsvYnhjTb
这里是哪个编译器?
c++ compiler-errors language-lawyer function-declaration default-arguments
我正在 Laravel 项目中开发 VueJS 3,并且正在使用一个 JS 文件,该文件为我提供了用于 Markdown 工具栏的元素。基本上,它是一组函数,为我提供了应用所选降价选项的按钮。一切工作正常,但我收到了那些我希望它们消失的控制台错误。
它们都与此类似:
Failed to resolve component: md-linedivider
If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement.
at <Markdowntoolbar>
at <Article onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< undefined > >
at <BaseTransition mode="out-in" appear=false persisted=false ... >
at <Transition enter-active-class="animate__animated animate__fadeInLeft" leave-active-class="animate__animated animate__bounceOutUp" mode="out-in" >
at <RouterView>
at <App>
at <Bodycomponent>
at <App>Run Code Online (Sandbox Code Playgroud)
这就是说,应通过compilerOptions.isCustomElement 将 md-linedivider 元素从组件解析中排除。我确实到处寻找解决方案,但只找到了这个,但我的 laravel 项目中没有 vue.config.js 来应用它。我尝试在 webpack.mis.js 和 app.js 中执行此操作,但没有成功。
有人有什么想法吗?
在我的AppDelegate中有一个我不明白的问题.RootViewController最初调用了ViewController,我改名了.该应用程序由许多ViewController组成,然后我介绍了一个UINavigationController.为什么会出现此错误?
NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle
/Users/XXXXXXXXXXXX/Library/Application Support/iPhone simulator/6.0/Applications/
B7A7D461-1CFE-4B05-AF32-00B65FCFFF49/XXXXXXXXXX.app> (loaded)'with name
'RootViewController''
*** First throw call stack:
(0x1992012 0x1357e7e 0x1991deb 0x4bafac 0x37fe37 0x380418 0x380648 0x380882 0
x380b2a 0x397ef5 0x397fdb x398286 0x398381 0x398eab 0x398fc9 0x399055 0x49e3ab
0x2ef92d 0x136b6b0 0x1f12fc0 0x1f0733c 0x1f12eaf 0x38e8cd 0x2d71a6 0x2d5cbf
0x2d5bd9 0x2d4e34 0x2d4c6e 0x2d5a29 0x2d8922 0x382fec 0x2cfbc4 0x2cfdbf
0x2cff55 0x2d8f67 0x2b30 0x29c7b7 0x29cda7 0x29dfab 0x2af315 0x2b024b 0x2a1cf8
0x1dbedf9 0x1dbead0 0x1907bf5 0x1907962 0x1938bb6 0x1937f44 0x1937e1b 0x29d7da
0x29f65c 0x269d 0x25c5)
ibc++abi.dylib: terminate called throwing …Run Code Online (Sandbox Code Playgroud) 我几乎不知道C++模板会发生什么,但我正在尝试实现一个函数,它在向量中搜索满足给定属性的元素(在这种情况下,搜索名称给定的元素).我在.h文件中的声明如下:
template <typename T>
T* find_name(std::vector<T*> v, std::string name);
Run Code Online (Sandbox Code Playgroud)
当我编译时,我在调用函数时遇到此链接器错误:
Error 1 error LNK2019: unresolved external symbol "class Item * __cdecl find_name<class Item>(class std::vector<class Item *,class std::allocator<class Item *> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??$find_name@VItem@@@@YAPAVItem@@V?$vector@PAVItem@@V?$allocator@PAVItem@@@std@@@std@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z) referenced in function "public: class Item * __thiscall Place::get_item(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?get_item@Place@@QAEPAVItem@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) place.obj Program2
Run Code Online (Sandbox Code Playgroud)
同样,我是模板的新手,所以我不知道会发生什么.我通过谷歌找到的LNK2019的所有实例都没有使用正确的库,但由于这是我自己的功能,我不明白为什么会发生这种情况.
另外,一个相关的问题:是否有办法制作模板参数,以便它必须是某个类的子类,即模板?
这个方法:
bool Point::Intersects(const Line& line) const {
return (line.ContainsPoint(*this, false));
}
Run Code Online (Sandbox Code Playgroud)
导致此错误:无法将'this'指针从'const Line'转换为'Line&'此更改:
bool Point::Intersects(const Line& line) const {
return const_cast<Line&>(line).ContainsPoint(*this, false);
}
Run Code Online (Sandbox Code Playgroud)
修复错误,但似乎不是解决问题的正确方法.为什么原始方法被认为是错误?
如果它有帮助,ContainsPoint(const Point& point, bool isInfinite)是非const,它调用的所有方法也是非const.
我有一个令人难以置信的恼人问题,这妨碍了我的工作流程.在我的项目中,我有"未声明的标识符用户"错误.它们都是对单个类的引用,特别是Theme类.我用我的导入检查了任何循环引用,没有.我真的很困惑.
以下是错误的屏幕截图.我会在构建日志中发布错误以获取更多详细信息,但是没有.它构建并运行得很好......

我试过清理,删除派生数据......有什么想法吗?
compiler-errors ×10
c++ ×4
ios ×3
xcode ×2
appdelegate ×1
apple-watch ×1
declaration ×1
ipad ×1
iphone ×1
java ×1
javascript ×1
laravel ×1
nib ×1
templates ×1
vue.js ×1
vuejs3 ×1
watchkit ×1