小编Pan*_*ang的帖子

c ++ set_intersection比较函数

使用函数时<algorithm>,通常会有一个额外的参数来自定义比较.但我不太了解有关参数的描述(set_intersection的文档).

二进制函数,它接受输入迭代器指向的两个类型的参数,并返回一个可转换为bool的值.返回的值指示第一个参数是否在其定义的特定严格弱顺序中被认为是在第二个参数之前.该函数不得修改其任何参数.这可以是函数指针或函数对象.

它描述了该函数应该返回两个参数的顺序.但是在匹配函数中呢,例如:

#include <algorithm>
#include <iostream>

using namespace std;

void print (const char* name, int* start, int* end) {
    cout << name << ": ";
    while (start < end) 
        cout << *start++ << ", ";
    cout << endl;
}

bool func1 (int a, int b) { return a==b; }
bool func2 (int a, int b) { return a+b == 8; }

int main() {
  int set1[6] = {0, 1, 2, 4, 2, 4};
  int set2[6] …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm comparison

5
推荐指数
1
解决办法
1186
查看次数

c ++变量没有在宏中命名类型

有这个代码:

#include <iostream>

int a=0;

#define F(f) \
  int t##f(int, int);\
  a ++;\
  int t##f(int i, int j)  

F(nn) {
    return i*j;
}

int main() {
 int b = tnn(3, 8);
 std::cout << a << b;
}
Run Code Online (Sandbox Code Playgroud)

编译时出错:

7:3: error: 'a' does not name a type
10:1: note: in expansion of macro 'F'
Run Code Online (Sandbox Code Playgroud)

为什么a宏在它扩展的位置不可见?

c++ macros

2
推荐指数
2
解决办法
907
查看次数

标签 统计

c++ ×2

algorithm ×1

comparison ×1

macros ×1