LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 09-28-2011, 08:26 AM   #1
shamjs
Member
 
Registered: Sep 2011
Posts: 93

Rep: Reputation: Disabled
using reference in formal parameter causes error,how to resolve it


Hi all,
if i try to use reference in formal parameter the compiler is reporting error as
error: no matching function for call to âPREDICT::GetModelAverageQResidualContribution3D(TNT::Array3D<double>)â

note: candidates are: TNT::Array2D<double> PREDICT::GetModelAverageQResidualContribution3D(TNT::Array3D<double>&)

Here is my code which defines the function
Code:
Array2D<REAL> GetModelAverageQResidualContribution3D(Array3D<REAL> & )  
	{
//here i have some code that uses model_xresiduals but i wont modify it.
//Array2D , Array3D are all user defined
}
here is the code that i invoke the above function
Code:
cout << pred.GetModelAverageQResidualContribution3D(val.GetResiduals());
if i remove "&" i wont get error,but i need to make that formal parameter as an alias(to actual argument) , plz suggest me to do this...........
waiting for your reply
 
Old 09-28-2011, 12:27 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
From the error message and the code it seems that you try to pass double to a code that is compiled for the REAL type (possibly float?). If the size of the floating point data is different in different parts of the code, it may be a good idea to make conversion.
 
Old 09-28-2011, 04:21 PM   #3
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by shamjs View Post
Code:
cout << pred.GetModelAverageQResidualContribution3D(val.GetResiduals());
Try something like:
Code:
TNT::Array3D<REAL> residuals = val.GetResiduals();

cout << pred.GetModelAverageQResidualContribution3D(residuals);
The other alternative is to redefine GetResiduals() to return a reference to a class data member of type TNT::Array3D<REAL>. Something like:
Code:
namespace TNT
{
   ...

   class Var
   {
   public:
      Array3D<REAL>& GetResiduals()
      {
         ...

         return myResiduals;
      }

   private:
      Array3D<REAL> myResiduals;
   };
}
 
Old 09-28-2011, 08:22 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
The error is saying that it can't make a reference from what you're passing. That means it's probably an rvalue (rvalues don't have to have addresses); in this case, val.GetResiduals() probably returns Array3D<REAL> which can only be used for a const reference or be passed by value. If possible, have the function take a const reference.
Kevin Barry
 
1 members found this post helpful.
Old 09-29-2011, 04:59 AM   #5
shamjs
Member
 
Registered: Sep 2011
Posts: 93

Original Poster
Rep: Reputation: Disabled
thanx for your suggestion ,it worked.....
 
  


Reply



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
[SOLVED] c++ passing pointer variable as a reference parameter chinho Programming 4 01-26-2011 08:19 PM
How can I resolve this error: make: *** [HelloWorld.o] error 127 for Eclipse C++ ? drcshavers Red Hat 4 06-05-2010 10:32 AM
unable to resolve compilation error;./List.c:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ amolgupta Programming 3 01-09-2009 10:09 AM
linux bash - how to use a dynamic parameter in shell parameter expansion expression nickleus Linux - General 2 08-21-2006 04:54 AM

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

All times are GMT -5. The time now is 07:53 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