Error message

L

Latina

Hi I am doing a program of sets using overloaded methods.
But I am having some error because supposedly the method isValid is
undeclared.
He is some part of my program.

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

class IntegerSet
{
private:
bool set[26];
int element;

public:
//Methods
IntegerSet(); //default
Constructor
IntegerSet(int x[], int k); //overload
constructor

bool isValue(int);
void insertElement(int);
void deleteElement(int);
void setString();
void inputSet();
};

//methos isValid
bool IntegerSet::isValid(int i)
{
return set;
}

Thanks.
 
L

Latina

Hi I am doing a program of sets using overloaded methods.
But I am having some error because supposedly the method isValid is
undeclared.
He is some part of my program.

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

class IntegerSet
{
private:
bool set[26];
int element;

public:
//Methods
IntegerSet(); //default constructor
IntegerSet(int x[], int k); //overload constructor

bool isValue(int);
void insertElement(int);
void deleteElement(int);
void setString();
void inputSet();

};

This is the error message pointing where the arrow is:
no `bool IntegerSet::isValid(int)' member function declared in class
`IntegerSet'
//methos isValid
bool IntegerSet::isValid(int i) --> {
return set;
}

Thanks.
 
L

Latina

isValue is not the same as isValid. One or the other is misspelled.
Or maybe both.

Michael

oops I didnt notice that, thanks
but I still have some other errors.

error: `isValid' undeclared (first use this function)

(where the arrow is pointing)


IntegerSet operator+(IntegerSet &right)
{
IntegerSet j;

for(int element=0; element<=25; element++)
{
--> if(isValid(element) || right.isValid(element))
j.insertElement(element);
}
return j;
}
 
M

Martin Engelmann

Latina said:
but I still have some other errors.

error: `isValid' undeclared (first use this function)

(where the arrow is pointing)


IntegerSet operator+(IntegerSet &right)
{
IntegerSet j;

for(int element=0; element<=25; element++)
{
--> if(isValid(element) || right.isValid(element))
j.insertElement(element);
}
return j;
}

Is operator+ a member of class IntegerSet? If it is, isValid will be
called with *this. If operator+ is not a member of class IntegerSet you
have to call it with an object.

Martin
 
L

Latina

Latina schrieb:










Is operator+ a member of class IntegerSet? If it is, isValid will be
called with *this. If operator+ is not a member of class IntegerSet you
have to call it with an object.

if i use *this gives me this error
--> invalid use of `this' in non-member function
 
M

Martin Engelmann

Latina said:
if i use *this gives me this error
--> invalid use of `this' in non-member function

So you should either make operator+ a member function of IntegerSet or
add a second parameter to the function.

IntegerSet IntegerSet::eek:perator+(IntegerSet &right)
(my recommendation)
or
IntegerSet operator+(IntegerSet &left, IntegerSet &right)

When using a non-member function you have to change the condition to
if(left.isValid(element) || right.isValid(element))
 
L

Latina

Latina schrieb:







So you should either make operator+ a member function of IntegerSet or
add a second parameter to the function.

IntegerSet IntegerSet::eek:perator+(IntegerSet &right)
(my recommendation)
or
IntegerSet operator+(IntegerSet &left, IntegerSet &right)

When using a non-member function you have to change the condition to
if(left.isValid(element) || right.isValid(element))- Hide quoted text -


Ok, I declared like this and this is the error I am getting
"expected init-declarator before '+' token ":

class IntegerSet
{
public:
//Operator methods.
IntegerSet &operator+(const IntegerSet &right);


//overloaded operator + to compute the union of two sets
--> IntegerSet IntegerSet::perator+(IntegerSet &right)
{
IntegerSet j;

for(int element=0; element<=25; element++)
{
if(isValid(element) || right.isValid(element))
j.insertElement(element);
}
return j;
}

But if I do it like this I am getting the same error
"expected init-declarator before '+' token"

//overloaded operator + to compute the union of two sets
--> IntegerSet perator+( &left, IntegerSet &right)
{
IntegerSet j;

for(int element=0; element<=25; element++)
{
if(left.isValid(element) || right.isValid(element))
j.insertElement(element);
}
return j;
}
 
L

Latina

Ok, I got it but now I am getting this error:
" passing `const IntegerSet' as `this' argument of `bool
IntegerSet::isValid(int)' discards qualifiers "


//overloaded operator + to compute the union of two sets
IntegerSet IntegerSet::eek:perator+(const IntegerSet &right)const
{
IntegerSet j;

for(int element=0; element<=25; element++)
{
--> if(isValid(element) || right.isValid(element))
j.insertElement(element);
}
return j;
}
 
V

Victor Bazarov

Latina said:
Ok, I got it but now I am getting this error:
" passing `const IntegerSet' as `this' argument of `bool
IntegerSet::isValid(int)' discards qualifiers "


//overloaded operator + to compute the union of two sets
IntegerSet IntegerSet::eek:perator+(const IntegerSet &right)const
{
IntegerSet j;

for(int element=0; element<=25; element++)
{
--> if(isValid(element) || right.isValid(element))
j.insertElement(element);
}
return j;
}

Most likely 'isValid' is not declared 'const' (unlike 'operator+'
here, for example)

V
 
L

Latina

I have another error where the arrow is.

Error: " `IntegerSet IntegerSet::eek:perator!(const IntegerSet&)' must
take `void' "

class IntegerSet
{
public:
//Operator methods.
IntegerSet operator + (const IntegerSet &)const; //Method
union
IntegerSet operator * (const IntegerSet &)const; //Method
intersection
--> IntegerSet operator ! (const IntegerSet &)const; //Method
complement

//overloaded operator ! to compute the complent of a set
IntegerSet IntegerSet::eek:perator!(IntegerSet &right)const
{
IntegerSet j;

for(int element=0; element<=25; element++)
{
if(!isValid(element))
j.insertElement(element);
}
return j;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Error message 2
C++ program error message 4
Errors 5
printing the union (help) 8
Printing help 2
Accelerated C++: Exercise 3-2 10
Lexical Analysis on C++ 1
How can I fix my pattern coding error in c++ 0

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,084
Latest member
HansGeorgi

Latest Threads

Top