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 11-24-2011, 01:23 AM   #1
shamjs
Member
 
Registered: Sep 2011
Posts: 93

Rep: Reputation: Disabled
pointer


Hi All,

i have some problem in pointers

here is my sample code.
Code:
/***predict.cpp********/
Array1D<REAL> CUnscXPredictor::CopyToArray1D(TXMatrix* inmatrix)
{
.
.
Array1D<REAL> amatrix(inmatrix->NumRows*inmatrix->NumColumns,inmatrix->aData); //line 1661	
	return amatrix;
}
Code:
/********olux.h*********/
typedef struct tagTMatrix1
{
	long   NumColumns;
	long   NumRows;
	long   NumPlanes;
	float*  aData;            /
	
} TXMatrix;
Code:
/*****tnt_array1d.h****/
template <class T>
		Array1D<T>::Array1D(long n, T *a) : v_(a), n_(n) , data_(v_.begin())
	{
#ifdef TNT_DEBUG
		std::cout << "Created Array1D(int n, T* a) \n";
#endif
	}
compiler is reporting error in line 1661 because of 2nd argument passed to the object.

predictor.cpp:1661: error: no matching function for call to âTNT::Array1D<double>::Array1D(long int, float*&)â
../inc/../inc/../../corenumeric/inc/utils/../jama/../tnt/tnt_array1d.h:107: note: candidates are: TNT::Array1D<T>::Array1D(const TNT::Array1D<T>&) [with T =
../inc/../inc/../../corenumeric/inc/utils/../jama/../tnt/tnt_array1d.h:135: note: TNT::Array1D<T>::Array1D(long int, T*) [with T = double]
../inc/../inc/../../corenumeric/inc/utils/../jama/../tnt/tnt_array1d.h:125: note: TNT::Array1D<T>::Array1D(long int, const T&) [with T = doub
../inc/../inc/../../corenumeric/inc/utils/../jama/../tnt/tnt_array1d.h:117: note: TNT::Array1D<T>::Array1D(long int) [with T = double]
../inc/../inc/../../corenumeric/inc/utils/../jama/../tnt/tnt_array1d.h:104: note: TNT::Array1D<T>::Array1D() [with T = double]


1> im having doubt at 2nd argument
inmatrix->aData
imatrix will finally points to address of aData
and this address will be passed to 2nd parameter of the below constructor which is a pointer type

Array1D<T>::Array1D(long n, T *a) : v_(a), n_(n) , data_(v_.begin())
{
}

hence address is passed to pointer but why compiler is raising error

2> im having doubt at 2nd parameter of error message
predictor.cpp:1661: error: no matching function for call to âTNT::Array1D<double>::Array1D(long int, float*&)â
../inc/../inc/../../corenumeric/inc/utils/../jama/../tnt/tnt_array1d.h:107

but when i replace the line 1661 with
float *ptr=inmatrix->aData;
Array1D<REAL> amatrix(inmatrix->NumRows*inmatrix->NumColumns,*ptr);

compiler wont report error.

plz guide what's the concept behind it and help me to fix this error..............

waiting for your reply.........

Last edited by shamjs; 11-24-2011 at 04:16 AM.
 
Old 11-24-2011, 03:06 AM   #2
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Quote:
Originally Posted by shamjs View Post
compiler is reporting error in line 1661 because of 2nd argument passed to the object.

predictor.cpp:1661: error: no matching function for call to âTNT::Array1D<double>::Array1D(long int, float*&)â
../inc/../inc/../../corenumeric/inc/utils/../jama/../tnt/tnt_array1d.h:107: note: candidates are: TNT::Array1D<T>::Array1D(const TNT::Array1D<T>&) [with T =
../inc/../inc/../../corenumeric/inc/utils/../jama/../tnt/tnt_array1d.h:135:../inc/../inc/../../corenumeric/inc/utils/../jama/../tnt/tnt_array3d.h:115: note: TNT::Array3D<T>::Array3D(long int, long int, long int, T) [
../inc/../inc/../../corenumeric/inc/utils/../jama/../tnt/tnt_array3d.h:94: note: TNT::Array3D<T>::Array3D(long int, long int, long int) [with
../inc/../inc/../../corenumeric/inc/utils/../jama/../tnt/tnt_array3d.h:83: note: TNT::Array3D<T>::Array3D() [with T = double]
TNT::Array1D<T>::Array1D(long int, T*) [with T = double]
You seem to have missed a vital portion of your error message - please post it in full.
 
Old 11-24-2011, 04:19 AM   #3
shamjs
Member
 
Registered: Sep 2011
Posts: 93

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by JohnGraham View Post
You seem to have missed a vital portion of your error message - please post it in full.
Sorry i have pasted wrong one..

please look at the same post,which i have edited now.
 
Old 11-24-2011, 04:26 AM   #4
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by g++
TNT::Array1D<T>::Array1D(long int, T*) [with T = double]
predictor.cpp:1661: error: no matching function for call to "TNT::Array1D<double>::Array1D(long int, float*&)"
Quote:
float* aData;
so... is it an array of float or double?
 
Old 11-24-2011, 04:39 AM   #5
shamjs
Member
 
Registered: Sep 2011
Posts: 93

Original Poster
Rep: Reputation: Disabled
its a float
but i dont why compiler is taking T=double
 
Old 11-24-2011, 04:41 AM   #6
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by shamjs View Post
its a float
but i dont why compiler is taking T=double
Code:
Array1D<REAL> amatrix(inmatrix->NumRows*inmatrix->NumColumns,inmatrix->aData); //line 1661
how is REAL defined?
 
Old 11-24-2011, 04:46 AM   #7
shamjs
Member
 
Registered: Sep 2011
Posts: 93

Original Poster
Rep: Reputation: Disabled
#define REAL float
 
Old 11-24-2011, 04:53 AM   #8
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by shamjs View Post
#define REAL float
Are you sure it doesn't get redefined somewhere?
Do you still get the error if you change the line 1661 to
Code:
Array1D<float> amatrix(inmatrix->NumRows*inmatrix->NumColumns,inmatrix->aData);
 
Old 11-24-2011, 05:26 AM   #9
shamjs
Member
 
Registered: Sep 2011
Posts: 93

Original Poster
Rep: Reputation: Disabled
when i changed to Array1D<float> amatrix(inmatrix->NumRows*inmatrix->NumColumns,inmatrix->aData); this

im getting error as
predictor.cpp:1662: error: conversion from âTNT::Array1D<float>â to non-scalar type âTNT::Array1D<double>â requested

similarly i checked by giving Array1D<double> amatrix(inmatrix->NumRows*inmatrix->NumColumns,inmatrix->aData);
when i executed this line
i got the same previous error, what i have posted earlier.........

thanx for your instant replies...............
 
Old 11-24-2011, 05:53 AM   #10
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by shamjs View Post
when i changed to Array1D<float> amatrix(inmatrix->NumRows*inmatrix->NumColumns,inmatrix->aData); this

im getting error as
predictor.cpp:1662: error: conversion from âTNT::Array1D<float>â to non-scalar type âTNT::Array1D<double>â requested
Oh, and you would have to also change the function to return array of float (obviously, float and REAL are not the same type):

Code:
Array1D<float> CUnscXPredictor::CopyToArray1D(TXMatrix* inmatrix)
so the CUnscXPredictor::CopyToArray1D has the same return type as amatrix

by the way I downloaded the tnt library and the following minimal example compiles without errors

Code:
#include "tnt.h"

class test {
	public:
	float *a;
	test(float* a_ = 0) : a(a_) {}
};

int main(){
	float f;
	test T(&f);
	long n(1);
	TNT::Array1D < float > (n, T.a);
	return 0;
}

Last edited by millgates; 11-24-2011 at 06:10 AM.
 
Old 11-24-2011, 06:37 AM   #11
shamjs
Member
 
Registered: Sep 2011
Posts: 93

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by millgates View Post
by the way I downloaded the tnt library and the following minimal example compiles without errors
you plz download this http://math.nist.gov/tnt/download.htmlwhich is source code(30kb)

the main problem is in
no matching function for call to âTNT::Array1D<double>::Array1D(long int, float*&)â of 2nd argument
means it is passing float*& argument at caller.

but at callee it needs
../inc/../inc/../../corenumeric/inc/utils/../jama/../tnt/tnt_array1d.h:135: note: TNT::Array1D<T>::Array1D(long int, T*) [with T = double]

T* type parameter.....
 
Old 11-24-2011, 06:46 AM   #12
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by shamjs View Post
you plz download this http://math.nist.gov/tnt/download.htmlwhich is source code(30kb)
yes, I know. That's what I downloaded

Quote:
Originally Posted by shamjs View Post
the main problem is in
no matching function for call to âTNT::Array1D<double>::Array1D(long int, float*&)â of 2nd argument
means it is passing float*& argument at caller.

but at callee it needs
../inc/../inc/../../corenumeric/inc/utils/../jama/../tnt/tnt_array1d.h:135: note: TNT::Array1D<T>::Array1D(long int, T*) [with T = double]

T* type parameter.....
yes, we already know that, too. The problem is, that the compiler believes that REAL is double. Therefore, amatrix is declared as an Array1D<double>
and the function CUnscXPredictor::CopyToArray1D returns an Array1D<double>, too, while inmatrix->aData is a pointer to float.
 
  


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
pointer to pointer segmentation fault Guilherme Programming 7 06-28-2009 09:47 AM
pass pointer,, return pointer??? blizunt7 Programming 3 07-23-2005 01:36 PM
returning data to main() via a pointer to a pointer. slzckboy Programming 3 05-30-2005 01:20 PM
hot to set value of pointer to pointer to a structure in C alix123 Programming 2 11-17-2004 06:40 AM
pointer to pointer question in c lawkh Programming 2 01-29-2004 10:26 AM

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

All times are GMT -5. The time now is 06:26 AM.

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