小编Dar*_*iey的帖子

在不同的数据类型上使用std :: transform

我有一个名为atom的自定义数据类型.我想用std :: transform来填充双向量,原子成员"number"是一个双倍的女巫.我得到错误"std :: vector :: iterator'没有名为'vec2'的成员",其中vec2是我的双向量.为什么是这样?甚至可以在变换中使用两种不同的数据类型吗?

atom.h

#ifndef _atom_
#define _atom_
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

class atom{

public:

    bool operator==(const atom rhs);
    double number;
    string name;

};
#endif
Run Code Online (Sandbox Code Playgroud)

atom.cpp

#include "atom.h"

atom::atom(){}

atom::~atom(){}

bool atom::operator==(const atom rhs){
    return this->name==rhs.name;

    } 
Run Code Online (Sandbox Code Playgroud)

transformation.h

#ifndef _transformation_
#define _transformation_
#include "atom.h"
#include <vector>
#include <algorithm>
using namespace std;


struct transformation{


    double operator() (atom a) const{

            return a.number;
        }



};
#endif  
Run Code Online (Sandbox Code Playgroud)

main.cpp中

int main(){

    vector<atom> vec;


    atom …
Run Code Online (Sandbox Code Playgroud)

c++ transform std custom-data-type

-1
推荐指数
1
解决办法
1195
查看次数

标签 统计

c++ ×1

custom-data-type ×1

std ×1

transform ×1