PDA

View Full Version : [C++] class definition



erotavlas
November 15th, 2010, 12:10 PM
Hi,

I have a problem inside a class definition. I get the following compile error,
In constructor `Auto::Iterator::Iterator(const Auto&) expected primary-expression before '=' token| but I can't understand where is the error.



class Auto {

public:



typedef std::map<std::vector<std::string>, float> AutoMap;

private:
AutoMap myAutoMap;

public:

class Iterator {
private:
typedef AutoMap::const_iterator iter;
const Auto* myAuto;

public:
Iterator(const Auto& myAuto_) {
myAuto = &myAuto_;
iter = myAuto->myAutoMap.begin();
}
};

friend class Iterator;


/*...*/

};

Thank you

GeneralZod
November 15th, 2010, 12:30 PM
Hi,

I have a problem inside a class definition. I get the following compile error,
In constructor `Auto::Iterator::Iterator(const Auto&) expected primary-expression before '=' token| but I can't understand where is the error.




class Iterator {
...
typedef AutoMap::const_iterator iter;
...

public:
Iterator(const Auto& myAuto_) {
...
iter = myAuto->myAutoMap.begin();
}
};



"iter" is a type, not an object, so can't be the target of an assignment.

erotavlas
November 15th, 2010, 02:52 PM
"iter" is a type, not an object, so can't be the target of an assignment.

Ok, you are right...
The following code is correct because the class Auto is a template?
Correct me If I say a ********...



template <typename I = Vector, typename T = float>
class Auto {

public:


typedef std::map<I, T> AutoMap;

private:
AutoMap myAutoMap;

public:

class Iterator {
private:
typename AutoMap::const_iterator iter;
const Auto<I,T>* myAuto;

public:
Iterator(const Auto& myAuto_) {
myAuto = &myAuto_;
iter = myAuto->myAutoMap.begin();
}
};

friend class Iterator;


/*...*/

};