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?
>Solution :
It means int foo = '3'; and int bar = 3; respectively.
But it’s not exactly equivalent, e.g. with classes = doesn’t permit explicit constructors.