在阅读此博客文章及其评论时,我注意到它举例说明了将特定的功能参数标记为已弃用的可能性,例如(摘自该文章):
// Deprecate a function parameter
int triple([[deprecated]] int x);
Run Code Online (Sandbox Code Playgroud)
现在我想知道,这种功能的好用例是什么?在该帖子或我搜索过的其他任何地方的评论中,没有人似乎有任何线索。
编辑:
要看到它的实际效果,有一个关于goldbolt的可编译示例
我试图为我的 Angular4 应用程序实现一个通用的 ErrorHandler,目的是显示一个对话框,其中包含有关我收到的错误的一些信息。
这是错误处理程序:
import { ErrorHandler, Injectable, Injector } from '@angular/core'
// import { Router } from '@angular/router'
import { MatDialog } from '@angular/material'
import { HttpErrorResponse } from '@angular/common/http'
import { MessageDialog } from './message.dialog'
// import { LoginService } from '../login/main.service'
@Injectable()
export class DialogErrorHandler implements ErrorHandler {
constructor(private injector: Injector) {
}
handleError(error: any): void {
let localError = error;
let finalMessage: string = "Errore sconosciuto";
let finalCallback: () => void = () => { …
Run Code Online (Sandbox Code Playgroud) #include <iostream>
using namespace std;
int main() {
int x = 5;
int* y = &x;
int& z = y;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
对于此代码,编译器给出以下错误int& z = y;
:
./example.cpp: In function 'int main()':
./example.cpp:7:11: error: invalid conversion from 'int*' to 'int' [-fpermissive]
7 | int& z = y;
| ^
| |
| int*
./example.cpp:7:11: error: cannot bind rvalue '(int)y' to 'int&'
Run Code Online (Sandbox Code Playgroud)
为什么?我知道为什么会出错,而且我知道如何解决它,我很好奇为什么编译器无法隐式执行转换,对我而言,我的意图似乎微不足道,是使指针和引用引用相同的内存位置。我想念什么极端情况吗?