简体   繁体   中英

Integer literal as parameters of function declaration in cpp

I'm almost familiar with c and c++ programming. Today I was searching about function declaration when I suddenly came across a strange syntax in c++ language.
I wrote below code:

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

I've never seen defining the literals as function parameters: So I expected to get compile error when I compile this program:

$ g++ file.cpp

But it compiled without any problem!
So I'm curious to know what's the meaning and usage of int foo('3'); and int bar(3); lines?

It means int foo = '3'; and int bar = 3; respectively.

But it's not exactly equivalent, eg with classes = doesn't permit explicit constructors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM