Passing an initialization list to a macro

前端 未结 3 2223
时光取名叫无心
时光取名叫无心 2021-02-18 18:07

Why doesn\'t the commented out line in the following program compile?

#include 
#include 
using namespace std;

#define F1(a) 1

in         


        
3条回答
  •  执念已碎
    2021-02-18 19:06

    A macro is not a function. It interprets your input vector{1,2,3} as 3 inputs, which are vector{1,2 and 3}. You can change this by making it an expression (vector{1,2,3}) (as you already did).

    Everything in parantheses is an expression and vector(...) is a (*special member-)function so the preprocessor sees it as one expression.

提交回复
热议问题