簡體   English   中英

Integer 文字作為 function 在 cpp 中聲明的參數

[英]Integer literal as parameters of function declaration in cpp

cc++編程我都差不多熟悉了。 今天在搜索 function 聲明時,突然發現c++語言中的一個奇怪語法。
我寫了下面的代碼:

#include <iostream>
using namespace std;
int foo('3');
int bar(3);
int main(){
    
}

我從未見過將文字定義為 function 參數:所以我預計在編譯此程序時會出現編譯錯誤:

$ g++ file.cpp

但是編譯沒有問題!
所以我很想知道int foo('3');含義用法是什么? int bar(3); 線?

這意味着int foo = '3'; int bar = 3; 分別。

但它並不完全等同,例如 classes =不允許explicit構造函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM