1

sorry if my question is to newbish, but i cant find a solution.

i have a class named Transition that have a map called inNext, and i want to print this Transition object, but i get an error about "cant find the begin or end members" (from map class)

class Transition{

public:
    Transition():inNext(){};
    ~Transition(){};

    map<string, string>& getTransition(){
        return inNext;
    }

    void setTransition(string a, string b){

        inNext.insert(pair<string,string>(a,b));
    }

    void printTransition(Transition a){
        map <string, string>::iterator it;
        for(it = a.begin(); it != a.end(); it++){

            cout << (*it).first << ","<<(*it).second << endl;
        }

    }


private:
    map<string, string> inNext;

};
4

2 回答 2

1

你的方法很奇怪:它是一个成员函数它需要另一个实例Transition(甚至无缘无故地复制它)作为参数。你可能想要

void print() {
    // you want to print the content of the map inNext:
    for(map <string, string>::iterator it = inNext.begin(); it != inNext.end(); it++) {
        cout << it->first << "," << it->second << endl;
    }
}

像这样调用:

Transition myTransition = ...;

myTransition.print();
于 2013-10-15T19:54:10.770 回答
0

begin并且不是你班级end的成员。std::map您需要调用a.inNext.begin()a.inNext.end()

于 2013-10-15T19:48:07.383 回答