View Full Version : Quick Question


Ender
06-07-02, 03:45 PM
Concider this


Hey guys, I havnet posted anything in a LONG while but...


I have this problem with some very basic code:


#include <fstream.h>
#include "apvector.h"
#include <stdlib.h>
#include <conio.h>


void main()
{

int moving=0, l, j;

apvector <char> mover [20];

//fill apvector with dots


for(int c=0; c<20; c++)
{
mover[c]='.';
}

mover[0]='x';

cout<<"Move your 'x'";
system("pause");

moving=getch();

if(moving == 75)
{
for(int k=0; k<20; k++)
{
error--------------> if( mover[k]=='x')
k=l;
}
mover[k]='.';
mover[k-1]='x';
}


if(moving == 77)
{
for(int h=0; h<20; h++)
{
error--------------> if( mover[h] == 'x')
h=j;
}
mover[h]='.';
mover[h+1]='x';
}

for(int d=0; d<19; d++)
{
error----------> cout << mover[d];
}
}


D:\CPrograms\MOver\mover.cpp(33) : error C2676: binary '==' : 'class apvector<char>' does not define this operator or a conversion to a type acceptable to the predefined operator

D:\CPrograms\MOver\mover.cpp(45) : error C2676: binary '==' : 'class apvector<char>' does not define this operator or a conversion to a type acceptable to the predefined operator

D:\CPrograms\MOver\mover.cpp(54) : error C2676: binary '<<' : 'class ostream_withassign' does not define this operator or a conversion to a type acceptable to the predefined operator


I'm just experimenting with this, if anyone has any ideas it would be greatly appreciated!

djonk
06-16-02, 04:40 PM
Hello Mr. Wiggins.

I'm not a 100 % certain about this. But it seems you are trying to compare your own class objects with chars. Is you apvector actually a char?

Otherwise it seems that you would need to define the operators "==" and "<<" for your class. This because the compiler can't know what to compare with what inside your class objects. It seems like the apvector is not a char and then they can't be compared (without a typecast of course).

For example (or someting similar)

class apvector{
char vect;

public:
apvector(char c) { vect = c; }
bool operator==(char c) { eturn vect==c}
}

Or is apvector a predefined class somewhere?

Maybe I've even misunderstood your question.

Ender
06-16-02, 10:49 PM
I figured it out thanks anyways!!