# Classes & Collections

Printable View

• 12-11-2007
Max_Payne
Classes & Collections
***Header Files:

Point.h
Code:

```#pragma once #include <iostream> using namespace std; class Point { private:         int x;         int y; public:         Point(void);         Point( int x, int y );         Point( const Point &xPoint );         ~Point(void);         void setX( int x );         int getX() const;         void setY( int y );         int getY() const;         Point & operator = ( const Point &xPoint );         bool includes( int cord_X, int cord_Y ) const;         void draw() const; };```

PointCollection.h
Code:

```#pragma once #include "Point.h" const int MAX = 100; class PointCollection { private:         Point pts[ MAX ];         int quantity; public:         PointCollection( void );         PointCollection( const PointCollection &xPointCollection );         ~PointCollection( void );         // To know how many Points are         // ..in the collection         int size() const;         PointCollection operator = ( const PointCollection &xPointCollection );                 Point &operator[]( int index );         const Point &operator[]( int index ) const;         bool isFull() const;         bool isEmpty() const;         bool includes( const Point &xPoint ) const;         int indexOf( const Point &xPoint ) const; };```
////////////////////////////////////////////////////////////////////////

***Source Files:

Point.cpp
Code:

```#include "Point.h" Point::Point( void ) {         this->x = 0;         this->y = 0; } Point::Point( int x, int y ) {         this->x = x;         this->y = y; } Point::Point( const Point &xPoint ) {         this->x = xPoint.x;         this->y = xPoint.x; } Point::~Point( void ){} // Destructor //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx void Point::setX( int x ) // set X {         this->x = x; } void Point::setY( int y ) // set Y {         this->y = y; } int Point::getX() const // get X {         return ( this->x ); } int Point::getY() const // get Y {         return ( this->y ); } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Point &Point::operator = ( const Point &xPoint ) {         this->x = xPoint.x;         this->y = xPoint.y;         return ( *this ); } bool Point::includes( int cord_X, int cord_Y ) const {         return ( this->x == cord_X && this->y == cord_Y ); } void Point::draw() const {         cout << '.'; }```

PointCollection.cpp
Code:

``` #include "PointCollection.h" PointCollection::PointCollection( void ) {         this->quantity = 0; } PointCollection::PointCollection( const PointCollection &xPointCollection ) {         this->quantity = xPointCollection.quantity;         for ( int i = 0; i < this->quantity; i++ )                 ( this->pts )[ i ] = ( xPointCollection.pts )[ i ]; } PointCollection::~PointCollection( void ) {} //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx int PointCollection::size() const {         return ( this->quantity ); } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Point &PointCollection::operator []( int index ) {         return ( ( this->pts )[ index ] ); } const Point &PointCollection::operator []( int index ) const {         return ( ( this->pts )[ index ] ); } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx PointCollection PointCollection::operator =( const PointCollection &xPointCollection ) {         this->quantity = xPointCollection.quantity;         for ( int i = 0; i < this->quantity; i++ )                 ( this->pts )[ i ] = ( xPointCollection.pts )[ i ];         return ( *this ); } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx bool PointCollection::isFull() const {         return ( this->quantity == MAX ); } bool PointCollection::isEmpty() const {         return ( this->quantity == 0 ); } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx bool Point::includes( const Point &xPoint ) const {         bool thisOne = false;         for ( int i = 0; i < this->quantity && ! thisOne; i++ )         {                 if ( ( *this )[ i ] == xPoint )                         thisOne = true;         }         return ( thisOne ); } int PointCollection::indexOf( const Point &xPoint ) const {         int index = -1;         for ( int i = 0; i < this->quantity && index == -1; i++ )         {                 if ( ( *this )[ i ] == xPoint )                         index = i;         }         return ( index ); }```

Main.cpp
Code:

```#include "PointCollection.h" int main () {         Point p1( 1, 1 ), p2( p1 );         p1.draw();         cout << "\n\n";         if ( p1.includes( 1, 1 ) == true )                 cout << "Point 1 & 2 are Equal" << "\n\n";         else                 cout << "Point 1 & 2 are NOT Equal" << "\n\n";         system("PAUSE");         return 0; } // end main```

This is the Error I'm Getting:
------ Build started: Project: Project_Dibujo, Configuration: Debug Win32 ------
Compiling...
Point.cpp
PointCollection.cpp
c:\documents and settings\mpayne007\my documents\visual studio 2005\projects\project_dibujo\project_dibujo\pointc ollection.cpp(85) : error C2511: 'bool Point::includes(const Point &) const' : overloaded member function not found in 'Point'
c:\documents and settings\mpayne007\my documents\visual studio 2005\projects\project_dibujo\project_dibujo\point. h(7) : see declaration of 'Point'
c:\documents and settings\mpayne007\my documents\visual studio 2005\projects\project_dibujo\project_dibujo\pointc ollection.cpp(103) : error C2784: 'bool std::operator ==(const std::allocator<_Ty> &,const std::allocator<_Other> &) throw()' : could not deduce template argument for 'const std::allocator<_Ty> &' from 'const Point'
c:\program files\microsoft visual studio 8\vc\include\xmemory(174) : see declaration of 'std::operator =='
c:\documents and settings\mpayne007\my documents\visual studio 2005\projects\project_dibujo\project_dibujo\pointc ollection.cpp(103) : error C2784: 'bool std::operator ==(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'const Point'
c:\program files\microsoft visual studio 8\vc\include\xutility(2143) : see declaration of 'std::operator =='
c:\documents and settings\mpayne007\my documents\visual studio 2005\projects\project_dibujo\project_dibujo\pointc ollection.cpp(103) : error C2784: 'bool std::operator ==(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const Point'
c:\program files\microsoft visual studio 8\vc\include\xutility(1826) : see declaration of 'std::operator =='
c:\documents and settings\mpayne007\my documents\visual studio 2005\projects\project_dibujo\project_dibujo\pointc ollection.cpp(103) : error C2784: 'bool std::operator ==(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const Point'
c:\program files\microsoft visual studio 8\vc\include\utility(60) : see declaration of 'std::operator =='
c:\documents and settings\mpayne007\my documents\visual studio 2005\projects\project_dibujo\project_dibujo\pointc ollection.cpp(103) : error C2676: binary '==' : 'const Point' does not define this operator or a conversion to a type acceptable to the predefined operator
Generating Code...
Compiling...
Main_.cpp
Generating Code...
Build log was saved at "file://c:\Documents and Settings\MPayne007\My Documents\Visual Studio 2005\Projects\Project_Dibujo\Project_Dibujo\Debug\ BuildLog.htm"
Project_Dibujo - 6 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
• 12-11-2007
Elysia
Yes, and you are expecting us to fix these errors for you? Is this your code? Do you have any understanding of why these errors appear? Do you know how templates and classes work?
• 12-11-2007
Max_Payne
I'm not expecting anyone to fix the problems. A Hint that would help me fix this problems would be good.

Don't worry about it. Someone from another forum gave me that hint that helped me solve these problems.

Your statement would have been valid if i haven't showed any effort but that's not the case here.

p.s: This doesn't have to do anything with Templates.
• 12-11-2007
MacGyver
Quote:

Originally Posted by Max_Payne
Your statement would have been valid if i haven't showed any effort but that's not the case here.

You showed zero effort here. You just dumped the code plus all the errors with nothing else added.

Same as you did here, which I assume is the another forum you speak of: http://forums.devx.com/showthread.php?t=165498
• 12-11-2007
Max_Payne
So besides making the code and showing it to you. what else do you want me to do?
• 12-11-2007
MacGyver
Give us some idea of what we're looking at. If you can't find the error and you are totally familiar with the code (assuming that you wrote it all) and you have the compiler message, then why do you assume we can figure it out? To do so requires us to slosh through the compiler errors as well as your code. ;)

Instead, tell us what you think the problem is related to, what the lines of code are in question (because I don't feel like counting X lines from the start of file Y in something this large. For smaller code examples, this isn't as much of a concern), and what you did to try to fix it (so we already know the beaten trails).
• 12-11-2007
Max_Payne
Well thanks anyway. But the problems were just some mistypes that i fixed and it's working.

I'll keep what you said in mind for future threads..

~Max
• 12-11-2007
Elysia
Quote:

Originally Posted by Max_Payne
p.s: This doesn't have to do anything with Templates.

This kinda just goes to show how little you know.
90&#37; of those error messages related to template functions in the STL.
You aren't supposed to dump them on us - you are supposed to ask if there's particular error you don't understand. Many of those errors were because you were incorrectly using the STL methods.
Plus you have a const function (or more), and you messed up a little with those, as well.

Take it like they say:
Learn what these errors means by perhaps asking and then try to fix the problem yourself. It will help you in the long run.