Okay I have a bunch of code below. Hope it comes across readable.
The problem I'm having is that in the lines under main():
cout << a << endl;
Is going into the code for IntArray(const IntArray&);. Without that function
these first 5 tests work fine. Of course I need that come test6().
Also something must be wrong with the deconstructor. If I comment it out my
program goes much further without crashing out.
And in case your wondering I can't modify any of the test#() functions.
Those came from the instructor.
Please rip it apart. Thanks.
*************** ******
My Class:
*************** ******
#include <iostream>
using namespace std;
class IntArray
{
private:
int arrayLow, arrayHigh; //low & high index of array
char name; //name of object
int *array; //pointer to
beggining of array
public:
IntArray(); //Constructor - create
array index 0-9
IntArray(int); //Constructor for arrays
starting at 0
IntArray(int, int); //Constructor for arrays not
starting at 0
IntArray(const IntArray&); //Constructor for making copy of
another IntArray object
~IntArray() {delete[] array;} //Default Deconstructor
int& IntArray::opera tor[](int); //Overload [] for
Assigning Values
int& IntArray::opera tor[](int) const;
void operator=(const IntArray&); //Overload = for
Assigning two IntArray Objects
int IntArray::opera tor==(IntArray) ; //Overload == for
Comparing Arrays
int IntArray::opera tor!=(IntArray) ; //Overload != for
Comparing Arrays
IntArray IntArray::opera tor+(IntArray); //Overload + for Adding
Arrays
void IntArray::opera tor+=(IntArray) ; //Overload +=
friend ostream& operator<<( ostream& theStream,IntAr ray
toPrint); //Overload <<
int low() const {return arrayLow;} //Returns lowest
index of array
int high() const {return arrayHigh;} //Returns
highest index of array
void setName(char myName) {name=myName;} //Sets name of
object
};
*************** ******
My Code for the Class:
*************** ******
#include "intarray.h "
using namespace std;
IntArray::IntAr ray()
{
arrayLow=0;
arrayHigh=9;
array=new int[arrayHigh-arrayLow+1];
}
IntArray::IntAr ray(int size)
{
arrayLow=0; //array starts at 0
arrayHigh=size-1; //highest index of array based on given
size
array=new int[size]; //create array memory locations
}
IntArray::IntAr ray(int low, int high)
{
arrayLow=low; //start of array index
arrayHigh=high; //end of array index
if(arrayHigh>=a rrayLow)
array=new int[arrayHigh-arrayLow+1]; //create array
memory locations
else
cout << "Low Array Boundry Higher than High Array
Boundry" << endl;
}
IntArray::IntAr ray(const IntArray& copyFrom)
{
arrayLow=copyFr om.arrayLow;
arrayHigh=copyF rom.arrayHigh;
array=new int[arrayHigh-arrayLow+1];
for(int i=arrayLow;i<ar rayHigh;++i)
array[i]=copyFrom.array[i];
}
int& IntArray::opera tor[] (int forLocation)
{
if(forLocation> =arrayHigh || forLocation<arr ayLow)
//Change to halt program - Array out of bounds
return array[arrayLow+forLoc ation];
else
return array[arrayLow+forLoc ation];
}
int& IntArray::opera tor[](int forLocation) const
{
if(forLocation> =arrayHigh || forLocation<arr ayLow)
//Change to halt program - Array out of bounds
return array[arrayLow+forLoc ation];
else
return array[arrayLow+forLoc ation];
}
void IntArray::opera tor=(const IntArray& copyFrom)
{
for(int i=arrayLow;i<ar rayHigh;++i)
array[i]=copyFrom.array[copyFrom.arrayL ow+i];
}
int IntArray::opera tor== (IntArray a)
{
if((arrayHigh-arrayLow)!=(a.h igh()-a.low()))
return 0; //Arrays not of same length
for(int i=arrayLow;i<ar rayHigh;i++)
{
if(array[i]!=a[a.low()+i])
return 0; //Two elements do not match
}
return 1; //All elements matched, return TRUE
}
int IntArray::opera tor!= (IntArray a)
{
if((arrayHigh-arrayLow)!=(a.h igh()-a.low()))
return 1; //Arrays not of same length
for(int i=arrayLow;i<ar rayHigh;i++)
{
if(array[i]!=a[a.low()+i])
return 1; //Two elements do not match
}
return 0; //All elements matched, return FALSE
}
IntArray IntArray::opera tor+ (IntArray b)
{
IntArray sum(arrayHigh-arrayLow);
for(int i=0;i<(arrayHig h-arrayLow);i++)
{
// sum[i]=array[arrayLow+i] + b[b.arrayLow()+i];
}
return sum;
}
void IntArray::opera tor+= (IntArray b)
{
for(int i=arrayLow;i<ar rayHigh;i++)
array[i]=array[i]+b[b.arrayLow+i];
}
ostream& operator<<(ostr eam& theStream, IntArray toPrint)
{
for(int i=toPrint.array Low;i<=toPrint. arrayHigh;++i)
theStream << "Index: " << i << "\tValue: "
<< toPrint[i] << endl;
return theStream;
}
*************** ******
What main() runs
*************** ******
void test1()
{
system("cls");
cout << "1. Array declared with single integer: IntArray a(10);" << endl <<
endl;
csis << "1. Array declared with single integer: IntArray a(10);" << endl <<
endl;
IntArray a(10);
for(int i = a.low(); i <= a.high(); i++)
a[i] = i * 10;
a.setName('a');
cout << a << endl;
csis << a << endl;
wait();
}
void test2()
{
system("cls");
cout << "2. Array declared with two integers: IntArray b(-3, 6);" << endl <<
endl;
csis << "2. Array declared with two integers: IntArray b(-3, 6);" << endl <<
endl;
IntArray b(-3, 6);
for(int i = b.low(); i <= b.high(); i++)
b[i] = i * 10;
b.setName('b');
cout << b << endl;
csis << b << endl;
wait();
}
void test3()
{
system("cls");
cout << "3. Array declared with two integers: IntArray c(6, 8);" << endl <<
endl;
csis << "3. Array declared with two integers: IntArray c(6, 8);" << endl <<
endl;
IntArray c(6, 8);
for(int i = c.low(); i <= c.high(); i++)
c[i] = i * 10;
c.setName('c');
cout << c << endl;
csis << c << endl;
wait();
}
void test4()
{
system("cls");
cout << "4. Array declared with two identical integers: IntArray d(5, 5);"
<< endl << endl;
csis << "4. Array declared with two identical integers: IntArray d(5, 5);"
<< endl << endl;
IntArray d(5, 5);
for(int i = d.low(); i <= d.high(); i++)
d[i] = i * 10;
d.setName('d');
cout << d << endl;
csis << d << endl;
wait();
}
void test5()
{
system("cls");
cout << "5. Array declared with no integers: IntArray z;" << endl << endl;
csis << "5. Array declared with no integers: IntArray z;" << endl << endl;
IntArray z;
for(int i = z.low(); i <= z.high(); i++)
z[i] = i * 10;
z.setName('z');
cout << z << endl;
csis << z << endl;
wait();
}
void test6()
{
system("cls");
cout << "6. Array declared with another object of type IntArray: IntArray
c(6, 8);" << endl;
cout << "
Intarray e(c);" << endl << endl;
csis << "6. Array declared with another object of type IntArray: IntArray
c(6, 8);" << endl;
csis << "
Intarray e(c);" << endl << endl;
IntArray c(6, 8);
for(int i = c.low(); i <= c.high(); i++)
c[i] = i * 10;
c.setName('c');
cout << c << endl;
csis << c << endl;
IntArray e(c);
e.setName('e');
cout << e << endl;
csis << e << endl;
wait();
}
Steve Evans
SDSU Foundation 2 2067
-Steve- wrote: Okay I have a bunch of code below. Hope it comes across readable.
The problem I'm having is that in the lines under main():
cout << a << endl;
Is going into the code for IntArray(const IntArray&);. Without that function these first 5 tests work fine. Of course I need that come test6().
Also something must be wrong with the deconstructor. If I comment it out my program goes much further without crashing out.
And in case your wondering I can't modify any of the test#() functions. Those came from the instructor.
Please rip it apart. Thanks.
-Steve-
Between the excess vertical whitespace and the lack of indentation, your
code is almost impossible to read. In order to get an appropriate
response, may I suggest you fix that and resubmit (hint: use spaces
instead of tabs; tabs often don't translate well across email).
Sorry,
--ag *************** ******
My Class:
*************** ******
#include <iostream>
using namespace std;
class IntArray
{
private:
int arrayLow, arrayHigh; //low & high index of array
char name; //name of object
int *array; //pointer to
beggining of array
public:
IntArray(); //Constructor - create
array index 0-9
IntArray(int); //Constructor for arrays
starting at 0
IntArray(int, int); //Constructor for arrays not
starting at 0
IntArray(const IntArray&); //Constructor for making copy of
another IntArray object
~IntArray() {delete[] array;} //Default Deconstructor
int& IntArray::opera tor[](int); //Overload [] for
Assigning Values
int& IntArray::opera tor[](int) const;
void operator=(const IntArray&); //Overload = for
Assigning two IntArray Objects
int IntArray::opera tor==(IntArray) ; //Overload == for
Comparing Arrays
int IntArray::opera tor!=(IntArray) ; //Overload != for
Comparing Arrays
IntArray IntArray::opera tor+(IntArray); //Overload + for Adding
Arrays
void IntArray::opera tor+=(IntArray) ; //Overload +=
friend ostream& operator<<( ostream& theStream,IntAr ray
toPrint); //Overload <<
int low() const {return arrayLow;} //Returns lowest
index of array
int high() const {return arrayHigh;} //Returns
highest index of array
void setName(char myName) {name=myName;} //Sets name of
object
};
*************** ******
My Code for the Class:
*************** ******
#include "intarray.h "
using namespace std;
IntArray::IntAr ray()
{
arrayLow=0;
arrayHigh=9;
array=new int[arrayHigh-arrayLow+1];
}
IntArray::IntAr ray(int size)
{
arrayLow=0; //array starts at 0
arrayHigh=size-1; //highest index of array based on given
size
array=new int[size]; //create array memory locations
}
IntArray::IntAr ray(int low, int high)
{
arrayLow=low; //start of array index
arrayHigh=high; //end of array index
if(arrayHigh>=a rrayLow)
array=new int[arrayHigh-arrayLow+1]; //create array
memory locations
else
cout << "Low Array Boundry Higher than High Array
Boundry" << endl;
}
IntArray::IntAr ray(const IntArray& copyFrom)
{
arrayLow=copyFr om.arrayLow;
arrayHigh=copyF rom.arrayHigh;
array=new int[arrayHigh-arrayLow+1];
for(int i=arrayLow;i<ar rayHigh;++i)
array[i]=copyFrom.array[i];
}
int& IntArray::opera tor[] (int forLocation)
{
if(forLocation> =arrayHigh || forLocation<arr ayLow)
//Change to halt program - Array out of bounds
return array[arrayLow+forLoc ation];
else
return array[arrayLow+forLoc ation];
}
int& IntArray::opera tor[](int forLocation) const
{
if(forLocation> =arrayHigh || forLocation<arr ayLow)
//Change to halt program - Array out of bounds
return array[arrayLow+forLoc ation];
else
return array[arrayLow+forLoc ation];
}
void IntArray::opera tor=(const IntArray& copyFrom)
{
for(int i=arrayLow;i<ar rayHigh;++i)
array[i]=copyFrom.array[copyFrom.arrayL ow+i];
}
int IntArray::opera tor== (IntArray a)
{
if((arrayHigh-arrayLow)!=(a.h igh()-a.low()))
return 0; //Arrays not of same length
for(int i=arrayLow;i<ar rayHigh;i++)
{
if(array[i]!=a[a.low()+i])
return 0; //Two elements do not match
}
return 1; //All elements matched, return TRUE
}
int IntArray::opera tor!= (IntArray a)
{
if((arrayHigh-arrayLow)!=(a.h igh()-a.low()))
return 1; //Arrays not of same length
for(int i=arrayLow;i<ar rayHigh;i++)
{
if(array[i]!=a[a.low()+i])
return 1; //Two elements do not match
}
return 0; //All elements matched, return FALSE
}
IntArray IntArray::opera tor+ (IntArray b)
{
IntArray sum(arrayHigh-arrayLow);
for(int i=0;i<(arrayHig h-arrayLow);i++)
{
// sum[i]=array[arrayLow+i] + b[b.arrayLow()+i];
}
return sum;
}
void IntArray::opera tor+= (IntArray b)
{
for(int i=arrayLow;i<ar rayHigh;i++)
array[i]=array[i]+b[b.arrayLow+i];
}
ostream& operator<<(ostr eam& theStream, IntArray toPrint)
{
for(int i=toPrint.array Low;i<=toPrint. arrayHigh;++i)
theStream << "Index: " << i << "\tValue: "
<< toPrint[i] << endl;
return theStream;
}
*************** ******
What main() runs
*************** ******
void test1()
{
system("cls");
cout << "1. Array declared with single integer: IntArray a(10);" << endl << endl;
csis << "1. Array declared with single integer: IntArray a(10);" << endl << endl;
IntArray a(10);
for(int i = a.low(); i <= a.high(); i++)
a[i] = i * 10;
a.setName('a');
cout << a << endl;
csis << a << endl;
wait();
}
void test2()
{
system("cls");
cout << "2. Array declared with two integers: IntArray b(-3, 6);" << endl << endl;
csis << "2. Array declared with two integers: IntArray b(-3, 6);" << endl << endl;
IntArray b(-3, 6);
for(int i = b.low(); i <= b.high(); i++)
b[i] = i * 10;
b.setName('b');
cout << b << endl;
csis << b << endl;
wait();
}
void test3()
{
system("cls");
cout << "3. Array declared with two integers: IntArray c(6, 8);" << endl << endl;
csis << "3. Array declared with two integers: IntArray c(6, 8);" << endl << endl;
IntArray c(6, 8);
for(int i = c.low(); i <= c.high(); i++)
c[i] = i * 10;
c.setName('c');
cout << c << endl;
csis << c << endl;
wait();
}
void test4()
{
system("cls");
cout << "4. Array declared with two identical integers: IntArray d(5, 5);" << endl << endl;
csis << "4. Array declared with two identical integers: IntArray d(5, 5);" << endl << endl;
IntArray d(5, 5);
for(int i = d.low(); i <= d.high(); i++)
d[i] = i * 10;
d.setName('d');
cout << d << endl;
csis << d << endl;
wait();
}
void test5()
{
system("cls");
cout << "5. Array declared with no integers: IntArray z;" << endl << endl;
csis << "5. Array declared with no integers: IntArray z;" << endl << endl;
IntArray z;
for(int i = z.low(); i <= z.high(); i++)
z[i] = i * 10;
z.setName('z');
cout << z << endl;
csis << z << endl;
wait();
}
void test6()
{
system("cls");
cout << "6. Array declared with another object of type IntArray: IntArray c(6, 8);" << endl;
cout << "
Intarray e(c);" << endl << endl;
csis << "6. Array declared with another object of type IntArray: IntArray c(6, 8);" << endl;
csis << "
Intarray e(c);" << endl << endl;
IntArray c(6, 8);
for(int i = c.low(); i <= c.high(); i++)
c[i] = i * 10;
c.setName('c');
cout << c << endl;
csis << c << endl;
IntArray e(c);
e.setName('e');
cout << e << endl;
csis << e << endl;
wait();
}
Steve Evans
SDSU Foundation
--
Artie Gold -- Austin, Texas
I've posted it on the web: http://planetevans.com/operators.htm
However I'm going to break down the problem more and post the seperate
problems. Thanks.
"Artie Gold" <ar*******@aust in.rr.com> wrote in message
news:3F******** **@austin.rr.co m... -Steve- wrote: Okay I have a bunch of code below. Hope it comes across readable.
The problem I'm having is that in the lines under main():
cout << a << endl;
Is going into the code for IntArray(const IntArray&);. Without that
function these first 5 tests work fine. Of course I need that come test6().
Also something must be wrong with the deconstructor. If I comment it out
my program goes much further without crashing out.
And in case your wondering I can't modify any of the test#() functions. Those came from the instructor.
Please rip it apart. Thanks.
-Steve-
Between the excess vertical whitespace and the lack of indentation, your code is almost impossible to read. In order to get an appropriate response, may I suggest you fix that and resubmit (hint: use spaces instead of tabs; tabs often don't translate well across email).
Sorry, --ag
*************** ******
My Class:
*************** ******
#include <iostream>
using namespace std;
class IntArray
{
private:
int arrayLow, arrayHigh; //low & high index of array
char name; //name of object
int *array; //pointer to
beggining of array
public:
IntArray(); //Constructor - create
array index 0-9
IntArray(int); //Constructor for arrays
starting at 0
IntArray(int, int); //Constructor for arrays not
starting at 0
IntArray(const IntArray&); //Constructor for making copy of
another IntArray object
~IntArray() {delete[] array;} //Default Deconstructor
int& IntArray::opera tor[](int); //Overload [] for
Assigning Values
int& IntArray::opera tor[](int) const;
void operator=(const IntArray&); //Overload = for
Assigning two IntArray Objects
int IntArray::opera tor==(IntArray) ; //Overload == for
Comparing Arrays
int IntArray::opera tor!=(IntArray) ; //Overload != for
Comparing Arrays
IntArray IntArray::opera tor+(IntArray); //Overload + for Adding
Arrays
void IntArray::opera tor+=(IntArray) ; //Overload +=
friend ostream& operator<<( ostream& theStream,IntAr ray
toPrint); //Overload <<
int low() const {return arrayLow;} //Returns lowest
index of array
int high() const {return arrayHigh;} //Returns
highest index of array
void setName(char myName) {name=myName;} //Sets name of
object
};
*************** ******
My Code for the Class:
*************** ******
#include "intarray.h "
using namespace std;
IntArray::IntAr ray()
{
arrayLow=0;
arrayHigh=9;
array=new int[arrayHigh-arrayLow+1];
}
IntArray::IntAr ray(int size)
{
arrayLow=0; //array starts at 0
arrayHigh=size-1; //highest index of array based on given
size
array=new int[size]; //create array memory locations
}
IntArray::IntAr ray(int low, int high)
{
arrayLow=low; //start of array index
arrayHigh=high; //end of array index
if(arrayHigh>=a rrayLow)
array=new int[arrayHigh-arrayLow+1]; //create array
memory locations
else
cout << "Low Array Boundry Higher than High Array
Boundry" << endl;
}
IntArray::IntAr ray(const IntArray& copyFrom)
{
arrayLow=copyFr om.arrayLow;
arrayHigh=copyF rom.arrayHigh;
array=new int[arrayHigh-arrayLow+1];
for(int i=arrayLow;i<ar rayHigh;++i)
array[i]=copyFrom.array[i];
}
int& IntArray::opera tor[] (int forLocation)
{
if(forLocation> =arrayHigh || forLocation<arr ayLow)
//Change to halt program - Array out of bounds
return array[arrayLow+forLoc ation];
else
return array[arrayLow+forLoc ation];
}
int& IntArray::opera tor[](int forLocation) const
{
if(forLocation> =arrayHigh || forLocation<arr ayLow)
//Change to halt program - Array out of bounds
return array[arrayLow+forLoc ation];
else
return array[arrayLow+forLoc ation];
}
void IntArray::opera tor=(const IntArray& copyFrom)
{
for(int i=arrayLow;i<ar rayHigh;++i)
array[i]=copyFrom.array[copyFrom.arrayL ow+i];
}
int IntArray::opera tor== (IntArray a)
{
if((arrayHigh-arrayLow)!=(a.h igh()-a.low()))
return 0; //Arrays not of same length
for(int i=arrayLow;i<ar rayHigh;i++)
{
if(array[i]!=a[a.low()+i])
return 0; //Two elements do not match
}
return 1; //All elements matched, return TRUE
}
int IntArray::opera tor!= (IntArray a)
{
if((arrayHigh-arrayLow)!=(a.h igh()-a.low()))
return 1; //Arrays not of same length
for(int i=arrayLow;i<ar rayHigh;i++)
{
if(array[i]!=a[a.low()+i])
return 1; //Two elements do not match
}
return 0; //All elements matched, return FALSE
}
IntArray IntArray::opera tor+ (IntArray b)
{
IntArray sum(arrayHigh-arrayLow);
for(int i=0;i<(arrayHig h-arrayLow);i++)
{
// sum[i]=array[arrayLow+i] + b[b.arrayLow()+i];
}
return sum;
}
void IntArray::opera tor+= (IntArray b)
{
for(int i=arrayLow;i<ar rayHigh;i++)
array[i]=array[i]+b[b.arrayLow+i];
}
ostream& operator<<(ostr eam& theStream, IntArray toPrint)
{
for(int i=toPrint.array Low;i<=toPrint. arrayHigh;++i)
theStream << "Index: " << i << "\tValue: "
<< toPrint[i] << endl;
return theStream;
}
*************** ******
What main() runs
*************** ******
void test1()
{
system("cls");
cout << "1. Array declared with single integer: IntArray a(10);" << endl
<< endl;
csis << "1. Array declared with single integer: IntArray a(10);" << endl
<< endl;
IntArray a(10);
for(int i = a.low(); i <= a.high(); i++)
a[i] = i * 10;
a.setName('a');
cout << a << endl;
csis << a << endl;
wait();
}
void test2()
{
system("cls");
cout << "2. Array declared with two integers: IntArray b(-3, 6);" <<
endl << endl;
csis << "2. Array declared with two integers: IntArray b(-3, 6);" <<
endl << endl;
IntArray b(-3, 6);
for(int i = b.low(); i <= b.high(); i++)
b[i] = i * 10;
b.setName('b');
cout << b << endl;
csis << b << endl;
wait();
}
void test3()
{
system("cls");
cout << "3. Array declared with two integers: IntArray c(6, 8);" << endl
<< endl;
csis << "3. Array declared with two integers: IntArray c(6, 8);" << endl
<< endl;
IntArray c(6, 8);
for(int i = c.low(); i <= c.high(); i++)
c[i] = i * 10;
c.setName('c');
cout << c << endl;
csis << c << endl;
wait();
}
void test4()
{
system("cls");
cout << "4. Array declared with two identical integers: IntArray d(5,
5);" << endl << endl;
csis << "4. Array declared with two identical integers: IntArray d(5,
5);" << endl << endl;
IntArray d(5, 5);
for(int i = d.low(); i <= d.high(); i++)
d[i] = i * 10;
d.setName('d');
cout << d << endl;
csis << d << endl;
wait();
}
void test5()
{
system("cls");
cout << "5. Array declared with no integers: IntArray z;" << endl <<
endl; csis << "5. Array declared with no integers: IntArray z;" << endl <<
endl; IntArray z;
for(int i = z.low(); i <= z.high(); i++)
z[i] = i * 10;
z.setName('z');
cout << z << endl;
csis << z << endl;
wait();
}
void test6()
{
system("cls");
cout << "6. Array declared with another object of type IntArray:
IntArray c(6, 8);" << endl;
cout << "
Intarray e(c);" << endl << endl;
csis << "6. Array declared with another object of type IntArray:
IntArray c(6, 8);" << endl;
csis << "
Intarray e(c);" << endl << endl;
IntArray c(6, 8);
for(int i = c.low(); i <= c.high(); i++)
c[i] = i * 10;
c.setName('c');
cout << c << endl;
csis << c << endl;
IntArray e(c);
e.setName('e');
cout << e << endl;
csis << e << endl;
wait();
}
Steve Evans
SDSU Foundation
-- Artie Gold -- Austin, Texas This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Andy Jarrell |
last post by:
I'm trying to inherit from a specific class that has an overloaded operator. The problem I'm getting is that certain
overloaded operators don't seem to come with the inheritance. For example:
// TestA.h ---------------------------------------
#include <iostream>
enum Aval
{
FIRST_VALUE,
|
by: N4M |
last post by:
Dear,
I have problems with overloaded operators ++() and --(). MSVC++ 6.0
compiler gives errors, one is shown as below:
"
c:\data\c++\mygraphs\graph.h(182) : error C2555: 'CGraphNodeIter::++'
: overriding virtual function differs from 'CGraphNodeIterI::++' only
by return type or calling convention
c:\data\c++\mygraphs\graph.h(141) : see declaration of
'CGraphNodeIterI'
"
|
by: Brad Eck |
last post by:
"The only operators that cannot be overloaded
are :: (scope resolution), . (member selection), and .* (member
selection through pointer to function). Quoting from Stroustrup's 3rd
edition of _The C++ Programming Language_, section 11.2 (page 263),
these three operators 'take a name, rather than a value, as their
second operand and provide the primary means of referring to members.
Allowing them to be overloaded would lead to subtleties.'"...
|
by: masood.iqbal |
last post by:
I have a few questions regarding overloaded typecast
operators and copy constructors that I would like an
answer for. Thanks in advance.
Masood
(1) In some examples that I have seen pertaining to
casting class A to class B, the implementation of the
|
by: masood.iqbal |
last post by:
Please help me with this doubt that I have regarding overloaded
operators. Sometimes they are member functions and sometimes they are
friends (e.g. see the code snippet from Stroustrup, Second Edition that
I have posted to comp.sources.d). How do we decide which is more
appropriate? Why are the overloaded "<<" and ">>" operators always
friends?
Also, what is an appropriate application for the overloaded function
call operator?
| |
by: maadhuu |
last post by:
hi
i wasnt to know the answer for the following.
now ,u can overload all the operators which are basically determined at
runtime (coz' of whch operators like sizeof())cannot be overloaded.
now my doubt is , if u have something like
p->a ....where p(say) is a pointer of a user defined type, then u can
overload this because p is determined at runtime ???is this right ???
also if "a" is an object of the some user defined class,
|
by: ambar.shome |
last post by:
Hi,
As you know there are few operators in C++ which cant be overloaded.
They are:
.., .*, ::, ?: , new , delete , sizeof , typeid , static_casr ,
dynamic_cast , const_cast , reinterpret_cast .
Theremust be some reason for this restriction for each of the
|
by: Alex Zhitlenok |
last post by:
Hi,
My question is how to resolve in C# ambiguous overloaded operators?
Let say, I have two unrelated classes A and B, each one implements
overloaded operator + with the first parameter of type A, and the
second one of type B. Let say, these are not my classes and I know
nothing about the implementation. As system doesn't know what code
must be used for resolving the language construction a+b (where A a;
and B b;), it returns "The call...
|
by: raylopez99 |
last post by:
I need an example of a managed overloaded assignment operator for a
reference class, so I can equate two classes A1 and A2, say called
ARefClass, in this manner: A1=A2;. For some strange reason my C++.NET
2.0 textbook does not have one. I tried to build one using the format
as taught in my regular C++ book, but I keep getting compiler errors.
Some errors claim (contrary to my book) that you cannot use a static
function, that you must...
|
by: iluvatar |
last post by:
Hi all.
I have written a 3d-vector class (for 3-dimensional space) and I have
overloaded the arihtmetic operators like +, +=, * and so on. Also, the
constructor works with doubles and has default arguments.
In my class, the operator = works for another vector (just copying the
elements), and for a double: in this cases each element of the vector
will be equal to the double. Example:
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |