[galib] Re: GA1DArrayGenome

claudia cgbarnov at yahoo.com
Wed Aug 11 17:32:34 EDT 2004


Hello,

The == and != operators should be declared const:
   int operator ==(const Point & p) const { ... }
   int operator !=(const Point & p) const { ... }

Hope this helps!

Regards,
Claudia


 --- galib-request at mit.edu wrote: 
> 
> Date: Tue, 10 Aug 2004 10:01:26 +0200
> From: Andre Baumgart
> <andre.baumgart at ti.uni-mannheim.de>
> To: galib at mit.edu
> Subject: [galib] GA1DArrayGenome
> Message-ID: <411880D6.6040600 at ti.uni-mannheim.de>
> Content-Type: text/plain; charset=us-ascii;
> format=flowed
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Precedence: list
> Reply-To: andre.baumgart at ti.uni-mannheim.de
> Message: 2
> 
> Hi
> 
> I tried to use the GA1DArrayGenome with my own Type
> Point.
> 
> GA1DArrayGenome<Point> genome(20);
> 
> According to the documentation the Point class
> should have included 
> definitions of the operator !=, == , = and the copy
> constructor. Below 
> are the gcc error output and the class definition.
> 
> Thanx in advance if anybody has an idea how this can
> be solved.
> 
> Andre
> 
> 
>
----------------------------------------------------------------
> 
> class Point: The operators are defined only dummy!
> 
> 
> class Point {
> 
> protected:
>    float _x, _y, _z;
> 
> public:
>    Point(){ }
>    Point(int i){}
>    Point(float x, float y, float z) { _x = x; _y =
> y; _z = z; }
>    Point(const Point & p) { _x = p._x; _y = p._y; _z
> = p._z; }
> 
>    Point & operator =(const Point & p) { return
> *this; }
>    int operator ==(const Point & p) { return 0; }
>    int operator !=(const Point & p) { return 0; }
> 
>    ~Point() {}
> 
>    float x() const { return _x; }
>    float y() const { return _y; }
>    float z() const { return _z; }
>    float x(float val) { return _x=val; }
>    float y(float val) { return _y=val; }
>    float z(float val) { return _z=val; }
> 
>    friend ostream & operator<<(ostream & os, const
> Point & p){
>      os << "(" << p._x << ", " << p._y << ", " <<
> p._z << ")";
>      return os;
>    }
> 
> 
> };
> 
> --------------------------------
> 
> gcc messages:
> 
> (OSSPx_SteadyStateGA.cpp is the file where the
> GA1DArrayGenome is called!)
> 
> 
> g++ -I/usr/include -I/usr/include/g++-3 -O0 -Wall -g
> -c 
> -fmessage-length=0 -Wno-deprecated -O -fexceptions 
> -oOSSP/OSSPx_SteadyStateGA.o
> ../OSSP/OSSPx_SteadyStateGA.cpp
> /usr/local/include/ga/GA1DArrayGenome.C: In static
> member function 
> `static float
> GA1DArrayGenome<T>::ElementComparator(const
> GAGenome&, 
> const GAGenome&) [with T = Point]':
> 
> /usr/local/include/ga/GA1DArrayGenome.C:49:  
> instantiated from 
> `GA1DArrayGenome<T>::GA1DArrayGenome(unsigned int,
> float (*)(GAGenome&), 
> void*) [with T = Point]'
> 
> ../OSSP/OSSPx_SteadyStateGA.cpp:102:   instantiated
> from here
> /usr/local/include/ga/GA1DArrayGenome.C:452: error:
> passing `const 
> Point' as `this' argument of `int
> Point::operator==(const Point&)' 
> discards qualifiers
> 
> 
> 
> -----------------------
> 
> 
> 
> ------------------------------
> 
> _______________________________________________
> galib mailing list
> galib at mit.edu
> http://mailman.mit.edu/mailman/listinfo/galib
> 
> 
> End of galib Digest, Vol 14, Issue 4
> ************************************
>  


	
	
		
___________________________________________________________ALL-NEW Yahoo! Messenger - all new features - even more fun!  http://uk.messenger.yahoo.com


More information about the galib mailing list