c++ - Mixing inline and macro functions -


i've decided try something. know macros evil , should avoided wanted see what's going happen if such thing.

#include <iostream> using namespace std; inline void add(int x, int y) { cout << "inline: " << x + y << endl; } #define add(x,y) ( cout << "macro: " << x + y << endl )  int main() {     add(3,5); } 

it outputs:

macro: 8 

if comment out #define line inline starts working, , output turns inline: 8.

my question is, why compiler decides use macro function instead of inline. thank you!

i'm using linux mint 18.2, g++ 5.4.0, no parameters g++ -g t2.cpp -o t2.

macro substitution performed via pre-processor before compilation. compiler never sees add(3,5) - sees macro expansion.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -