Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,926 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,898 people online right now. Registration is fast and FREE... Join Now!




Classes & Collections

 
Reply to this topicStart new topic

Classes & Collections

Max_Payne
10 Dec, 2007 - 10:17 PM
Post #1

D.I.C Head
**

Joined: 19 Oct, 2007
Posts: 51


My Contributions
***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\pointcollection.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\pointcollection.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\pointcollection.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\pointcollection.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\pointcollection.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\pointcollection.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 ==========


This post has been edited by Max_Payne: 10 Dec, 2007 - 10:19 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 02:58PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month