469,357 Members | 1,565 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,357 developers. It's quick & easy.

Ambiguous call again

I am having an "ambiguous call to overloaded function" error again.

This is the function:

int nGetProfWidth (int ncols, unsigned ProfSpec)
{
if ((ProfSpec & PROF_2d) == 0)
return ncols;
return int(sqrt(ncols)); //HERE THE ERROR IS THROWN
}

When I want to have an integer returned (as in the code above - at least
I think it should return an integer), how should I rewrite this code?

Anna
Oct 25 '08 #1
32 1884
Anna Smidt wrote:
I am having an "ambiguous call to overloaded function" error again.

This is the function:

int nGetProfWidth (int ncols, unsigned ProfSpec)
{
if ((ProfSpec & PROF_2d) == 0)
return ncols;
return int(sqrt(ncols)); //HERE THE ERROR IS THROWN
}

When I want to have an integer returned (as in the code above - at least
I think it should return an integer), how should I rewrite this code?
Anna:

return int(sqrt(double(ncols)));

You do know that most integers do not have an exact integer square root?

--
David Wilkinson
Visual C++ MVP
Oct 25 '08 #2
You do know that most integers do not have an exact integer square root?

Thanks and...
No, I did not know that. But I was wrong in the first place already
anyway because I was thinking of a VB6 integer which isn't equal to
VC++ integers as far as I know. I'm already tired enough to drop on the
table, so I will look it up tomorrow morning (yes, I have a C++ book :-)

Anna
Oct 25 '08 #3
Oh, I have a question before I go to bed:

double hypotenuse = sqrt( square(p.y - q.y) + square(p.x - q.x) );

Why is there a space after "sqrt(" and before the last ")"?
Oct 25 '08 #4
Okay, 1 last question:

MatView Mat::viewAsSquare ()
{
size_t ncols = size_t(sqrt(this->nelems()));
// check that can square properly (assertion is not essential but
protects the user)
ASSERT(ncols * ncols == this->nelems());
return MatView(*this, 0, 0, ncols, ncols, ncols);
}

The compiler tells me

error C2514: 'size_t' : class has no constructors

Why? Sorry for my many questions...
Anna
Oct 25 '08 #5
Anna Smidt wrote:
>You do know that most integers do not have an exact integer square root?

Thanks and...
No, I did not know that. But I was wrong in the first place already
anyway because I was thinking of a VB6 integer which isn't equal to VC++
integers as far as I know. I'm already tired enough to drop on the
table, so I will look it up tomorrow morning (yes, I have a C++ book :-)
Anna:

This has nothing to do with computer languages; it's just math. What is the
integer square root of 20? According to your formula it is 4. This may be the
answer you want; only you know that.

--
David Wilkinson
Visual C++ MVP
Oct 25 '08 #6
Anna Smidt wrote:
Oh, I have a question before I go to bed:

double hypotenuse = sqrt( square(p.y - q.y) + square(p.x - q.x) );

Why is there a space after "sqrt(" and before the last ")"?
Anna:

White space (of this kind) is ignored in C and C++ expressions.

--
David Wilkinson
Visual C++ MVP
Oct 25 '08 #7
Anna Smidt wrote:
Okay, 1 last question:

MatView Mat::viewAsSquare ()
{
size_t ncols = size_t(sqrt(this->nelems()));
// check that can square properly (assertion is not essential but
protects the user)
ASSERT(ncols * ncols == this->nelems());
return MatView(*this, 0, 0, ncols, ncols, ncols);
}

The compiler tells me

error C2514: 'size_t' : class has no constructors
Anna:

I cannot reproduce this on VS2008. What compiler version are you using?

--
David Wilkinson
Visual C++ MVP
Oct 25 '08 #8

"Anna Smidt" <a.*****@nospamgmail.comha scritto nel messaggio
news:%2****************@TK2MSFTNGP02.phx.gbl...
Okay, 1 last question:

MatView Mat::viewAsSquare ()
{
size_t ncols = size_t(sqrt(this->nelems()));
Try:

size_t ncols = static_cast< size_t >( sqrt( this->nelems() ) );

Giovanni
Oct 25 '08 #9

"Anna Smidt" <a.*****@nospamgmail.comha scritto nel messaggio
news:OV**************@TK2MSFTNGP04.phx.gbl...
Oh, I have a question before I go to bed:

double hypotenuse = sqrt( square(p.y - q.y) + square(p.x - q.x) );

Why is there a space after "sqrt(" and before the last ")"?
For readability of code.

Giovanni
Oct 25 '08 #10
I cannot reproduce this on VS2008. What compiler version are you using?
Where do I find this info?

Oct 25 '08 #11
Try:
>
size_t ncols = static_cast< size_t >( sqrt( this->nelems() ) );

Giovanni
This doesn't help.
Oct 25 '08 #12
Anna Smidt wrote:
>
>I cannot reproduce this on VS2008. What compiler version are you using?

Where do I find this info?
Anna:

I really meant just what version of Visual Studio are you using. If you really
do not know, select "About Microsoft Visual Studio" (or some such) from the Help
menu.

Could you provide a complete example illustrating this problem?

Something like

#include <math.h>

int main()
{
int n = 100;
size_t ncols = size_t(sqrt(double(n)));
ncols; // prevent unused variable warning
return 0;
}

This code compiles fine for me on VS2008. Does it for you?

--
David Wilkinson
Visual C++ MVP
Oct 25 '08 #13
Anna Smidt wrote:
Oh, I have a question before I go to bed:

double hypotenuse = sqrt( square(p.y - q.y) + square(p.x - q.x) );

Why is there a space after "sqrt(" and before the last ")"?
Because some people believe that it makes to code easier to read.

They are wrong. :-)
And it confuses beginners...
Bo Persson
Oct 25 '08 #14
Because some people believe that it makes to code easier to read.
They are wrong. :-)
And it confuses beginners...
Agreed :-)
Oct 25 '08 #15
Oh, sorry, VC2008 here.
Oct 25 '08 #16
Yes, it works for me.

But I don't know what else I could provide but the code below.
As far as I understand it, MatView Mat::viewAsSquare() requires code
from "all.hpp", right?
Should I post the code from "all.hpp"?
Anna

#include "all.hpp"

static const bool USE_EQ_DOUBLES = true; // 1 to for match within
tolerance
static const char *MAT_PRINT_FORMAT = "%8.4f "; // default mat print format

namespace GslMat

//-----------------------------------------------------------------------------
MatView Mat::viewAsSquare ()
{
// size_t ncols = size_t(sqrt(this->nelems()));
size_t ncols = static_cast< size_t >( sqrt( this->nelems() ) );
// check that can square properly (assertion is not essential but
protects the user)
ASSERT(ncols * ncols == this->nelems());
return MatView(*this, 0, 0, ncols, ncols, ncols);
}

Oct 25 '08 #17
Anna Smidt wrote:
Oh, sorry, VC2008 here.
Anna:

And what about a complete compilable example?

When you provide a sample that depends on stuff not present in the sample, then
it is not possible to test your code as given, so the responder has to create a
compilable example which might (for some unknown reason) not exhibit the problem.

If you create the self-contained example yourself, and post that, then everybody
can be on the same page. But very often, the exercise of creating a
self-contained example will allow you to solve the problem for yourself.

--
David Wilkinson
Visual C++ MVP
Oct 25 '08 #18
Anna Smidt wrote:
Yes, it works for me.

But I don't know what else I could provide but the code below.
As far as I understand it, MatView Mat::viewAsSquare() requires code
from "all.hpp", right?
Should I post the code from "all.hpp"?
Anna

#include "all.hpp"

static const bool USE_EQ_DOUBLES = true; // 1 to for match within
tolerance
static const char *MAT_PRINT_FORMAT = "%8.4f "; // default mat print
format

namespace GslMat

//-----------------------------------------------------------------------------

MatView Mat::viewAsSquare ()
{
// size_t ncols = size_t(sqrt(this->nelems()));
size_t ncols = static_cast< size_t >( sqrt( this->nelems() ) );
// check that can square properly (assertion is not essential but
protects the user)
ASSERT(ncols * ncols == this->nelems());
return MatView(*this, 0, 0, ncols, ncols, ncols);
}
Anna:

If my simpler example works for you, the it is really up to *you* to figure out
what is between the simple example and your code. We cannot do that because we
do not have the code.

But since your code is at namespace and class scope, perhaps you have done
something to redefine size_t in this scope.

What happens if you do

::size_t ncols = static_cast< ::size_t >( sqrt( this->nelems() ) );

?

By the way, why are you not getting the ambiguous call on the sqrt here? What is
the type of this->nelems?

--
David Wilkinson
Visual C++ MVP
Oct 25 '08 #19
Thank god, the constructor error is gone!! Thanks very much!
By the way, why are you not getting the ambiguous call on the sqrt here?
I do get the ambiguous call error in the line you suggested:
Error 6 error C2668: 'sqrt' : ambiguous call to overloaded function
cmat.cpp 1101 ASMModel

Now this is one of the last bugs remaining.
What is the type of this->nelems?
I don't know, the code is so huge and I am so newbie to C++ that I have
not yet been able to figure out where nelems originates from.

Anna

Oct 25 '08 #20

"Bo Persson" <bo*@gmb.dkha scritto nel messaggio
news:6m************@mid.individual.net...
Because some people believe that it makes to code easier to read.

They are wrong. :-)
:-)

So, I just think that readability is a matter of personal preference... :)

<latin>De gustibus non disputandum est.</latin>

Giovanni

Oct 25 '08 #21

"Anna Smidt" <a.*****@nospamgmail.comha scritto nel messaggio
news:OQ**************@TK2MSFTNGP05.phx.gbl...
>Try:

size_t ncols = static_cast< size_t >( sqrt( this->nelems() ) );

Giovanni

This doesn't help.
OK, so I think that there is some problem with nelems() return value, as
David W. already pointed out.

You should post the prototype of nelems() method.

Giovanni

Oct 25 '08 #22

"Anna Smidt" <a.*****@nospamgmail.comha scritto nel messaggio
news:%2****************@TK2MSFTNGP03.phx.gbl...
Thank god, the constructor error is gone!! Thanks very much!
>By the way, why are you not getting the ambiguous call on the sqrt here?
I do get the ambiguous call error in the line you suggested:
Error 6 error C2668: 'sqrt' : ambiguous call to overloaded function
cmat.cpp 1101 ASMModel
You may try using ::sqrt() or std::sqrt() instead.

Giovanni
Oct 25 '08 #23
Until I know better, I will use double() to resolve the problem. When I
know more C++, I will find out if that's correct or if I have to use a
different conversion.
Oct 25 '08 #24

"Anna Smidt" <a.*****@nospamgmail.comha scritto nel messaggio
news:%2****************@TK2MSFTNGP03.phx.gbl...
>What is the type of this->nelems?
I don't know, the code is so huge and I am so newbie to C++ that I have
not yet been able to figure out where nelems originates from.
I would suggest you to use Visual Assist X from Wholetomato:

http://www.wholetomato.com/

There is a trial download available.

Your coding productivity will increase a lot thanks to VAX.

In this particular case, you can put the cursor on nelems() and press
CTRL+G, and you will be sent to the definition of that method.

Giovanni

Oct 25 '08 #25
I am not sure if I have found out correctly:

MatView (double other[], size_t nelems, char *sIsRowVec=NULL): Mat()
{
sIsRowVec? init(other, 0, 0, 1, nelems, 1): init(other, 0, 0, nelems, 1);
}
Does this tell me what type of nelems are?
Anna
Oct 25 '08 #26
Anna Smidt wrote:
Thank god, the constructor error is gone!! Thanks very much!
>By the way, why are you not getting the ambiguous call on the sqrt here?
I do get the ambiguous call error in the line you suggested:
Error 6 error C2668: 'sqrt' : ambiguous call to overloaded
function cmat.cpp 1101 ASMModel

Now this is one of the last bugs remaining.
>What is the type of this->nelems?
I don't know, the code is so huge and I am so newbie to C++ that I have
not yet been able to figure out where nelems originates from.
Anna:

1. Clearly nelems() is a method of the class Mat; can you not find it in the
class definition? Do a Visual Studio search for it if you do not see it.

2. However, it seems to me that nelems() must return the number of elements of
the matrix (i.e. nrows*ncols). Taking the square root can only make sense if the
matrix is square (nrows == ncols), in which case why not just use nrows or ncols?

By the way, next time you start a new thread you should use the group

microsoft.public.vc.language

The group you are using (microsoft.public.dotnet.languages.vc) is intended for
the C++/CLI language which targets the .NET platform (and which you are not using).

--
David Wilkinson
Visual C++ MVP
Oct 25 '08 #27

"Bo Persson" <bo*@gmb.dkha scritto nel messaggio
news:6m************@mid.individual.net...
Anna Smidt wrote:
>Oh, I have a question before I go to bed:

double hypotenuse = sqrt( square(p.y - q.y) + square(p.x - q.x) );

Why is there a space after "sqrt(" and before the last ")"?

Because some people believe that it makes to code easier to read.

They are wrong. :-)
It seems that Google C++ style guide agress with you, too :)

http://google-styleguide.googlecode....Function_Calls

Giovanni


Oct 25 '08 #28

"Anna Smidt" <a.*****@nospamgmail.comha scritto nel messaggio
news:ua**************@TK2MSFTNGP05.phx.gbl...
>I am not sure if I have found out correctly:

MatView (double other[], size_t nelems, char *sIsRowVec=NULL): Mat()
{
sIsRowVec? init(other, 0, 0, 1, nelems, 1): init(other, 0, 0, nelems, 1);
}
Does this tell me what type of nelems are?
No.

You posted this code:
MatView Mat::viewAsSquare ()
{
size_t ncols = size_t(sqrt(this->nelems()));
so: nelems() should be a member function of Mat class or some class from
which Mat class is derived.

Giovanni
Oct 25 '08 #29
Anna Smidt wrote:
I am not sure if I have found out correctly:

MatView (double other[], size_t nelems, char *sIsRowVec=NULL): Mat()
{
sIsRowVec? init(other, 0, 0, 1, nelems, 1): init(other, 0, 0,
nelems, 1);
}
Does this tell me what type of nelems are?
Anna:

No. This nelems is just a dummy variable name. The nelems in your expression is
a method, as you can tell from the parentheses on this->nelems().

Anna, you seem a little out of your depth:

Math-wise
C++-wise
Visual Studio-wise

What are you trying to do exactly? It seems that you are trying to use an
external library that does not appear to be written very well. This is not an
easy thing to do. Maybe you should be tackling something simpler?

--
David Wilkinson
Visual C++ MVP
Oct 25 '08 #30
I am sorry, but it's overwhelming... my first days at C++.
I want to target .NET after I have resolved my problems, but I see that
I should only post .NET specific questions, ok...
But I still don't know what is .NET and what's not.
1. Clearly nelems() is a method of the class Mat; can you not find it in
the class definition? Do a Visual Studio search for it if you do not see
it.
The problem is that I am not sure if I have found the correct thing.
I do have a Mat.cpp, is that the correct location, or what should I
search for?

Anna
Oct 25 '08 #31
Anna Smidt wrote:
I am sorry, but it's overwhelming... my first days at C++.
I want to target .NET after I have resolved my problems, but I see that
I should only post .NET specific questions, ok...
But I still don't know what is .NET and what's not.
>1. Clearly nelems() is a method of the class Mat; can you not find it
in the class definition? Do a Visual Studio search for it if you do
not see it.

The problem is that I am not sure if I have found the correct thing.
I do have a Mat.cpp, is that the correct location, or what should I
search for?

Anna:

The class definition should be in the header file (Mat.h perhaps, or Mat.hpp).
In it you will find the declaration of the elems() method. You should also find
the implementation Mat::elems() in Mat.cpp (unless the method is defined inline
in the header file).

But you can use Visual Studio to search your entire solution for elems():

Edit Menu->Find and Replace->Find in Files

You might also search for

class Mat (for the class definition)
Mat::nelems() (for the implemtation of elems())

It really seems to me that you should work on your C++ and Visual Studio skills
before tackling some large external library (that does not appear to be written
very well).

--
David Wilkinson
Visual C++ MVP
Oct 25 '08 #32
"Out of your depth", hahaha, this is very true.
I know VC++ since a few days only.
But I want/ have to get this project done. I learn the most when I do
complicated things.

Anna
Oct 25 '08 #33

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by xuatla | last post: by
1 post views Thread by Alex Zhitlenok | last post: by
reply views Thread by Michi Henning | last post: by
3 posts views Thread by Arpan | last post: by
4 posts views Thread by Chameleon | last post: by
8 posts views Thread by xtrigger303 | last post: by
9 posts views Thread by sebastian | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.