在帮我看看const的使用吧
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
class HE_edge
{
public:
inline bool operator == ( const HE_edge &ea);
inline HE_edge *next() const;
// 这个地方为什么不能用const啊?
inline void setnext(//const? HE_edge *next);
inline void seta( const int a);
inline int a() const;
private:
HE_edge *next_;
int a_;
};
//这个地方啊>
inline void HE_edge::setnext(//const HE_edge *next)
{
this->next_ = next;
}
inline void HE_edge::seta( const int a)
{
this->a_ = a;
}
inline bool HE_edge::operator ==(const HE_edge &ea)
{
return ( this->next_ == ea.next() && this->a_ == ea.a() );
}
inline HE_edge *HE_edge::next() const
{
return this->next_;
}
inline int HE_edge::a() const
{
return a_;
}
int main()
{
HE_edge value;
HE_edge *edgel = new HE_edge;
HE_edge ia[10];
for(int i = 0; i < 10 ; ++i)
{
if( i % 2 == 0)
{
ia[i].seta(0);
ia[i].setnext(NULL);
}
else
{
ia[i].seta(i);
ia[i].setnext(edgel);
}
}
value.seta(0);
value.setnext(NULL);
vector<HE_edge> vec( ia, ia + 10 );
vector<HE_edge>::iterator vec_iter;
vec_iter = remove( vec.begin(), vec.end(), value);
vec.erase( vec_iter, vec.end() );
vec_iter = vec.begin();
int m = 0;
for(; vec_iter != vec.end(); ++vec_iter )
{
m ++;
cout<<vec_iter->a()<<endl;
}
return 0;
}
那个地方怎么才用const呢?
用了回有下面的错误:
error C2440: '=' : cannot convert from 'const class HE_edge *' to 'class HE_edge *'
Conversion loses qualifiers