473,395 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Errors

Hi I am doing a program oveloraded operator.
I am having a few errors on it.

Error1: request for member `insertElement' in `S1set', which is of
non-
class type `IntegerSet[26]'

Error2: no matching function for call to `IntegerSet::operator+
(IntegerSet[26])'

Here is my program:
class IntegerSet
{
private:
bool set[26];
int element;

public:
//Operator methods.
IntegerSet operator + (const IntegerSet &)const;//method union

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

bool isValid(int)const;
void insertElement(int);
void deleteElement(int);
void setString();
void inputSet();
};
IntegerSet set();

IntegerSet::IntegerSet()
{
for(element=0; element>=25; element++)
set[element]= false;
}

IntegerSet::IntegerSet(int x[], int k)
{
for(element=0; element>=25; element++)
set[element]= false;
for(int j=0; j<k; j++)
{
element=x[j];
set[element]= true;
}
}

bool IntegerSet::isValid(int i)const
{
return set[i];
}

//insert element to a set
void IntegerSet::insertElement(int element)
{
set[element]=true;
}

//delete element of a set
void IntegerSet::deleteElement(int element)
{
set[element]=false;
}

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

for(int element=0; element<=25; element++)
{
if(isValid(element) || right.isValid(element))
j.insertElement(element);
}
return j;
}
int main()
{
IntegerSet run;
IntegerSet S1set[26];
IntegerSet S2set[26];
IntegerSet S3set[26];
IntegerSet Sset[26];

for(int i=2; i<=20; i+2)
S1set.insertElement(); <--Error 1

for(int k=6; k<=21; k+3)
S2set.insertElement(); <--Error 1

for(int j=3; j<=18; j+6)
S3set.insertElement(); <--Error 1

for(int z=0; z<=25; z++)
Sset.insertElement(); <--Error 1

run.inputSet();
int choice;

cout<<"\n WELCOME to the INTEGER SET PROGRAM\n";
cout<<"\n\nSelect one of these choices\n";
cout<<" 0. Create set \n";
cout<<" 1. Find Union \n";
cin>>choice;

if(choice==0)
{
int temp, ele;
int newSet[26];

cout<<"Enter how many elements you want in the set: "<<endl;
cin>>ele;

for(int i=0; i<ele; i++)
{
cout<<i+1;
cin>>temp;
newSet[i]=temp;
}
}
else if(choice==1)
{
char a, b, c, d, e,;
int option;

cout<<"Select one of this choices";
cout<<"a. To find the union of the set you enter and the set
'S'";
cout<<"b. To find the union of the set you enter and the set
'S1'";
cout<<"c. To find the union of the set you enter and the set
'S2'";
cout<<"d. To find the union of the set you enter and the set
'S3'";
cin>>option;
if(option=='a'||option=='A')
{
run.operator+(Sset); <--Error 2
}
else if(option=='b'||option=='B')
{
run.operator+(S1set); <--Error 2
}
else if(option=='c'||option=='C')
{
run.operator+(S2set); <--Error 2
}
else if(option=='d'||option=='D')
{
run.operator+(S3set); <--Error 2
}
}

return 0;
}
I hope some one can help me.

Nov 12 '07 #1
2 1396
On Tue, 13 Nov 2007 09:35:27 +0000, James Kanze wrote:
Tadeusz B. Kopec wrote:
>On Sun, 11 Nov 2007 21:46:46 -0800, Latina wrote:
Hi I am doing a program oveloraded operator. I am having a few errors
on it.
class IntegerSet
{
private:
bool set[26];
[snip]
>Second - it's wasting space. Use std::vector<boolor if you want a
fixed size - std::bitset.

As has often been pointed out, std::vector<boolis broken, and should
be avoided. And it's likely to take up just as much, or more space than
the original code. (On my machine, I get sizeof(bool) == 1,
sizeof(std::vector<bool>) == 40. And that doesn't count the memory
dynamically allocated by std::vector.)
OK. I thought that vector<boolnot being a container isn't a problem for
the use that is made in this class, but anyway it sacrifices speed for
(probable) space gain and it's a premature optimisation (if it is an
optimisation).

[snip]
IntegerSet::IntegerSet()
{
for(element=0; element>=25; element++)
set[element]= false;
}
The only thing this function does is assigning 0 to element.

It initializes the set to empty. Seems like a reasonable thing to do
for a default constructor. (Of course, using std::fill would be more
idiomatic. But his code seems quite reasonable.)
It would do this, if the loop condition was 'element <= 25'. As it is,
only the assignment to element will be executed. And of course using a
member as a loop controlling variable is a bad idea.
--
Tadeusz B. Kopec (tk****@NOSPAMPLEASElife.pl)
BOFH excuse #25:

Decreasing electron flux
Nov 13 '07 #2
On Nov 13, 9:19 pm, "Tadeusz B. Kopec" <tko...@NOSPAMPLEASElife.pl>
wrote:
On Tue, 13 Nov 2007 09:35:27 +0000, James Kanze wrote:
Tadeusz B. Kopec wrote:
On Sun, 11 Nov 2007 21:46:46 -0800, Latina wrote:
Hi I am doing a program oveloraded operator. I am having a few errors
on it.
class IntegerSet
{
private:
bool set[26];
[snip]
Second - it's wasting space. Use std::vector<boolor if you want a
fixed size - std::bitset.
As has often been pointed out, std::vector<boolis broken, and should
be avoided. And it's likely to take up just as much, or more space than
the original code. (On my machine, I get sizeof(bool) == 1,
sizeof(std::vector<bool>) == 40. And that doesn't count the memory
dynamically allocated by std::vector.)
OK. I thought that vector<boolnot being a container isn't a problem for
the use that is made in this class, but anyway it sacrifices speed for
(probable) space gain and it's a premature optimisation (if it is an
optimisation).
I don't think it would be an actual problem, but as a matter of
principle, I think it better to avoid vector<bool>, because it
looks like a container, even if it isn't one. Learning all its
quirks, to be sure of what you are doing, is probably more work
than just using the C style array (in this case, at least).
[snip]
IntegerSet::IntegerSet()
{
for(element=0; element>=25; element++)
set[element]= false;
}
The only thing this function does is assigning 0 to element.
It initializes the set to empty. Seems like a reasonable thing to do
for a default constructor. (Of course, using std::fill would be more
idiomatic. But his code seems quite reasonable.)
It would do this, if the loop condition was 'element <= 25'.
Oops. But that's obviously a typo.
As it is, only the assignment to element will be executed. And
of course using a member as a loop controlling variable is a
bad idea.
The overall structure of the code wasn't particularly good,
agreed. As I said, I'd use std::fill here. But the principle
of a loop isn't necessarily wrong, even if he miswrote it, and
didn't do it very cleanly.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Nov 14 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: mikey_boy | last post by:
Hello! Curious if anyone could give me a hand. I wrote this PHP script with makes a simple connection to a mysql database called firstdb and just pulls back the results and displays on the...
2
by: Trev | last post by:
SQL Server 2000 BE, Access 2002 FE. I want to write a stored procedure, that will among other things log errors to a table, I want to be able to report a summary of work done and errors to the...
10
by: Douglas Buchanan | last post by:
I am using the following code instead of a very lengthly select case statement. (I have a lot of lookup tables in a settings form that are selected from a ListBox. The data adapters are given a...
0
by: doli | last post by:
Hi, I have the following piece of code which iterates through the potential errors: i =0 For Each error_item in myConn.Errors DTSPackageLog.WriteStringToLog myConn.Errors(i).Description...
4
by: johnb41 | last post by:
I have a form with a bunch of textboxes. Each text box gets validated with the ErrorProvider. I want the form to process something ONLY when all the textboxes are valid. I found a solution,...
2
by: Samuel R. Neff | last post by:
Within the past few weeks we've been getting a lot of compiler errors in two classes when no errors actually exist. The error always reports as Name '_stepResizeRelocator' is not declared. ...
24
by: pat | last post by:
Hi everyone, I've got an exam in c++ in two days and one of the past questions is as follows. Identify 6 syntax and 2 possible runtime errors in this code: class demo {
8
by: ImOk | last post by:
I just have a question about trapping and retrying errors especially file locking or database locks or duplicate key errors. Is there a way after you trap an error to retry the same line that...
0
by: clemrock | last post by:
Help w/ errors.add_to_base between controller and model Hello, I'm having trouble in routing some errors between model and controller. The errors produced in the controller...
2
by: =?Utf-8?B?UmFuZHlz?= | last post by:
This just started when I updated to sp 1 working on a APS.net, Visual Studio 2008, c# Project. When I open a project, I get tons of Errors showing in the list 300+ if I double click on them I go...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.