473,320 Members | 1,950 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,320 software developers and data experts.

Problem in "+" operator.in doubly circular link list.

i have problem with this operator "+" in doubly circular link list.(i
think i have problem with return type).
error is of instantiate error.(mean type dismatch) if any one can help
me please reply.
template <class T>
DoublyCircularLinkList<TDoublyCircularLinkList<T>: : operator +
(const DoublyCircularLinkList& rhs) {
if (head==0 && rhs.head==0) {
return *this;
}
else if (rhs.head==0)
{

return *this;
}
else {

DoublyCircularLinkList<T>* Return;
Return-
>Insert(5);
DNode<T>*
TEMP=head;
do
{
Return-
>Insert(TEMP->Get());
TEMP=TEMP-
>GetNextPtr();
} while (TEMP!
=tail->GetNextPtr());
TEMP=rhs.head;
do
{
Return-
>Insert(TEMP->Get());
TEMP=TEMP-
>GetNextPtr();
} while (TEMP!
=rhs.tail->GetNextPtr());

return
*Return;
}

}
Sep 23 '08 #1
5 1393
template <class T>
DoublyCircularLinkList<TDoublyCircularLinkList<T>: : operator +
(const DoublyCircularLinkList& rhs) {
if (head==0 && rhs.head==0) {
return *this;
}
else if (rhs.head==0)
{
return *this;
}
else {
DoublyCircularLinkList<T>* Return;
Return->Insert(5);
DNode<T>* TEMP=head;
do
{
Return->Insert(TEMP->Get());
TEMP=TEMP->GetNextPtr();
} while (TEMP!=tail->GetNextPtr());
TEMP=rhs.head;
do
{
Return->Insert(TEMP->Get());
TEMP=TEMP->GetNextPtr();
} while (TEMP!=rhs.tail->GetNextPtr());
return *Return;
}
}
Sep 23 '08 #2
On Sep 23, 8:04*am, Muzammil <muzammilPeer...@gmail.comwrote:
template <class T>
DoublyCircularLinkList<TDoublyCircularLinkList<T>: : operator +
(const *DoublyCircularLinkList& rhs) {
// This initial 'if' is unnecessary based on the current
implementation shown here
if (head==0 && rhs.head==0) {
return *this;}

else if (rhs.head==0)
{
return *this;}

else {
// You never instantiate this pointer...
DoublyCircularLinkList<T>* Return;
Return->Insert(5);
DNode<T>* TEMP=head;
do
{
Return->Insert(TEMP->Get());
TEMP=TEMP->GetNextPtr();} while (TEMP!=tail->GetNextPtr());

TEMP=rhs.head;
do
{
Return->Insert(TEMP->Get());
TEMP=TEMP->GetNextPtr();

} while (TEMP!=rhs.tail->GetNextPtr());
return *Return;
}
}
First, you do not need 'if (head==0 && rhs.head==0)' and 'else if
(rhs.head==0)'. The behavior of both the conditions is the same and
the fact that 'head==0' does not change the action taken so all you
really need is the 'else if' case.

Second, you declare a DoublyCircularLinkList<Tpointer with this
line:
DoublyCircularLinkList<T>* Return;

However, you never actually instantiate the object before you try to
access it. That is, 'Return' is merely a pointer to memory that does
not "exist". You must first instantiate the memory something like
this:
DoublyCircularLinkList<T>* Return = new DoublyCircularLinkList<T>();

Also, bear in mind a few other things
1) You are returning by value, which means you will return a copy of
the object you have created and manipulated. That will reflect back on
the semantics of your copy constructor ( template< typename T >
DoublyCircularLinkList<T>() ). Be sure the copy constructor does what
you want it to do.
2) For the sake of clarity, think very seriously about NOT overloading
operator+ to concatenate. In general, operator+ means 'add' when
applied to primitive data types. Addition is the behavior that most
people expect. While it is true that various complex data types do
extend the meaning of operator+, your intent may not be obvious,
especially with a template class. Also, correct implementation is non-
trivial. Read "C++ Coding Standards" (Sutter, Alexandrescu), Item 26
for more discussion.
3) Why are you making this list in the first place? Unless you are
absolutely sure that you need it, why not try one of the standard
containers instead (vector, list, deque, etc)?

I hope that helps.
Sep 23 '08 #3
On Sep 23, 9:08*am, diamondback <christopher....@gmail.comwrote:
On Sep 23, 8:04*am, Muzammil <muzammilPeer...@gmail.comwrote:
template <class T>
DoublyCircularLinkList<TDoublyCircularLinkList<T>: : operator +
(const *DoublyCircularLinkList& rhs) {

// This initial 'if' is unnecessary based on the current
implementation shown here
if (head==0 && rhs.head==0) {
return *this;}
else if (rhs.head==0)
{
return *this;}
else {

// You never instantiate this pointer...
DoublyCircularLinkList<T>* Return;
Return->Insert(5);
DNode<T>* TEMP=head;
do
{
Return->Insert(TEMP->Get());
TEMP=TEMP->GetNextPtr();} while (TEMP!=tail->GetNextPtr());
TEMP=rhs.head;
do
{
Return->Insert(TEMP->Get());
TEMP=TEMP->GetNextPtr();
} while (TEMP!=rhs.tail->GetNextPtr());
return *Return;
}
}

First, you do not need 'if (head==0 && rhs.head==0)' and 'else if
(rhs.head==0)'. The behavior of both the conditions is the same and
the fact that 'head==0' does not change the action taken so all you
really need is the 'else if' case.

Second, you declare a DoublyCircularLinkList<Tpointer with this
line:
DoublyCircularLinkList<T>* Return;

However, you never actually instantiate the object before you try to
access it. That is, 'Return' is merely a pointer to memory that does
not "exist". You must first instantiate the memory something like
this:
DoublyCircularLinkList<T>* Return = new DoublyCircularLinkList<T>();

Also, bear in mind a few other things
1) You are returning by value, which means you will return a copy of
the object you have created and manipulated. That will reflect back on
the semantics of your copy constructor ( template< typename T >
DoublyCircularLinkList<T>() ). Be sure the copy constructor does what
you want it to do.
2) For the sake of clarity, think very seriously about NOT overloading
operator+ to concatenate. In general, operator+ means 'add' when
applied to primitive data types. Addition is the behavior that most
people expect. While it is true that various complex data types do
extend the meaning of operator+, your intent may not be obvious,
especially with a template class. Also, correct implementation is non-
trivial. Read "C++ Coding Standards" (Sutter, Alexandrescu), Item 26
for more discussion.
3) Why are you making this list in the first place? Unless you are
absolutely sure that you need it, why not try one of the standard
containers instead (vector, list, deque, etc)?

I hope that helps.
when i posted my questions most of time you all guys say why u not
use standard library functions.
reason i have to implement that particular function to understand what
the basics are not to use STL to make my work out....[mean i m student
of data structure course in undergraduate].
and thanks. for replying.
Sep 23 '08 #4
>
when i posted my questions most of time you all guys say why u not
use standard library functions.
reason i have to implement that particular function to understand what
the basics are not to use STL to make my work out....[mean i m student
of data structure course in undergraduate].
and thanks. for replying.
If "most of time", "all we guys" say why not use STL, then there is a
good reason for it, don't reinvent the wheel, there is already these
data structures and algorithms that STL provides which has been used
by engineers and thus considered efficient and bug free.

If your purpose is to learn, then why not mention it in your post?

Please also note that the person that responded had all good points
and did not respond with a one liner that just said "use STL".
Sep 23 '08 #5
On Sep 23, 2:11*pm, "news.aioe.org" <bigmur...@yahoo.comwrote:
when i posted my questions most of time *you all guys say why u not
use standard library functions.
reason i have to implement that particular function to understand what
the basics are not to use STL to make my work out....[mean i m student
of data structure course in undergraduate].
and thanks. for replying.

If "most of time", "all we guys" say why not use STL, then there is a
good reason for it, don't reinvent the wheel, there is already these
data structures and algorithms that STL provides which has been used
by engineers and thus considered efficient and bug free.

If your purpose is to learn, then why not mention it in your post?

Please also note that the person that responded had all good points
and did not respond with a one liner that just said "use STL".
ok.
Sep 24 '08 #6

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

Similar topics

5
by: George Copeland | last post by:
This is a request for help fixing a SQL Server 2000/ADO problem on Windows XP. I would appreciate any useful assistance. PROBLEM: SQL Server access on my machine fails as follows: 1. All of...
5
by: Michael Olea | last post by:
Here is a design problem I ran into this am - and I have cleaned the bathroom, scrubbed toilet sink and tub, windexed all glass, mopped the floor, and vacuumed the house - no dice, the problem is...
10
by: Michael Strorm | last post by:
Hi! I've been having problems with a DTD. Having had the Sun XML validator reject a document, I put it through 'xmllint' for more information. 'Xmllint' noted a problem with the DTD itself;...
2
by: mfilion | last post by:
Hey all, I have a problem with my the Form I built, hopefully someone here can help me out! I'm still a beginner, so bear with me! Here goes... The form contains many boxes, each of which...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
1
by: ApexData | last post by:
WatchOut for "Allow AutoCorrect" in your unbound combobox lookups. I am building a personnel database, and the last name of Ballance was causing the following message to popup, prohibiting me from...
17
by: radio1 | last post by:
Configuration: Access 2002 and SQL Server 2000 using a .ADP Project. I would VERY MUCH appreciate anyone's input into this problem I'm having. I have a form in Access that does not permit...
2
by: aRTx | last post by:
I have download a script "AutoIndex v 2.x" from http://autoindex.sourceforge.net ************ AutoIndex is a PHP script that makes a table that lists the files in a directory, and lets users...
5
by: annCooper | last post by:
Exchange Rates Source file: Exchange.cs Input file: Exchange.in Output file: Exchange.out Using money to pay for goods and services usually makes life easier, but sometimes people prefer to...
4
by: James Kanze | last post by:
On Nov 18, 5:50 pm, Pete Becker <p...@versatilecoding.comwrote: Has this changed in the latest draft. According to my copy of the standard (version 1998---out of date, I know), "The...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.