LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-07-2015, 11:57 AM   #1
allagar
LQ Newbie
 
Registered: May 2014
Posts: 11

Rep: Reputation: Disabled
compile error when using copy operator


Any idea why I should be getting this error?

I create 2 objects of the same class and then try to set one equal to the other. The class does have a overloaded copy operator?

TString temp1;
TString temp2;
temp1 = temp2;

error: no matching function for call to ‘TString::TString(TString)’
note: candidates are: TString::TString(TString&)
note: TString::TString(const char*)

const TString &TString:perator = (const TString &Src)
{
return Copy(Src);
}
arm-angstrom-linux-gnueabi-g++ (GCC) 4.2.4
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
Old 02-07-2015, 05:14 PM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Quote:
Originally Posted by allagar View Post
error: no matching function for call to ‘TString::TString(TString)’
note: candidates are: TString::TString(TString&)
note: TString::TString(const char*)
Does the class have a constructor which takes no arguments (since your sample code does not initialize the strings)?
 
Old 02-08-2015, 10:28 AM   #3
allagar
LQ Newbie
 
Registered: May 2014
Posts: 11

Original Poster
Rep: Reputation: Disabled
Yes it does have a default constructor taking no arguments:

TString::TString()
: TObj("String")
{
Len = 0;
MaxLen = 0;
Copy("");
}
 
Old 02-08-2015, 10:59 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,852
Blog Entries: 1

Rep: Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868
(Sorry wrong topic)
 
Old 02-08-2015, 11:28 AM   #5
allagar
LQ Newbie
 
Registered: May 2014
Posts: 11

Original Poster
Rep: Reputation: Disabled
Something I have found is if I use the following compiler version I do no get the error. But now there are issues regarding shared libriaris (libc) on my target system which is using applications compiled with the orginal cross compiler version. Any suggestions if I should change the code to work with the old compiler or use the new compiler for the specific application and add the new libraries which I am not sure how to do this without causing compatibility issues on the target. Any help is appreciated.

arm-linux-gnueabi-g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
Old 02-08-2015, 05:37 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,774

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by allagar View Post
error: no matching function for call to ‘TString::TString(TString)’
This looks like it's trying to use a copy constructor. Perhaps some compiler versions manage to optimize the copy away.
 
Old 02-09-2015, 01:30 AM   #7
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
pleas use code tags

this
Code:
const TString &TString:perator = (const TString &Src)
{
return Copy(Src);
}
is nonsense, the assignment operator has to return a reference to itself, aka return *this;


it is possible that this
Code:
TString temp1;
TString temp2;
temp1 = temp2;
becomes reordered and a constructor is called, especially if no useful code follows.
what optimization level did did you pass to the compiler? please provide complete information in your question.

however, if you think you need an assimgent operator you need also others

read this
http://en.wikipedia.org/wiki/Rule_of...programming%29

general, you do not implement your own string class, or if you do just for learning?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unary operator expected error greenpool Linux - Newbie 1 01-31-2012 07:36 PM
error: no match for operator hollyj Programming 3 10-09-2011 05:38 PM
unary operator expected error! Lynda_M Programming 3 11-29-2008 12:04 PM
Unary operator error hinetvenkat Programming 7 10-26-2008 11:22 AM
Binary operator expected - error mike9287 Linux - Newbie 9 07-17-2006 08:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration