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 32 2055
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
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
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 ")"?
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
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
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
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
"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
"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
I cannot reproduce this on VS2008. What compiler version are you using?
Where do I find this info?
Try:
>
size_t ncols = static_cast< size_t >( sqrt( this->nelems() ) );
Giovanni
This doesn't help.
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
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
Because some people believe that it makes to code easier to read.
They are wrong. :-)
And it confuses beginners...
Agreed :-)
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 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
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
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
"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
"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
"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
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.
"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
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
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
"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
"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
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
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
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
"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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: xuatla |
last post by:
compile error:
test1.cpp:21: error: ISO C++ says that
`T mtd::CDiffOperator::getdp(const mtd::mVector&, long int,
mtd::mBCTYPE) const'
and
`void mtd::CDiffOperator::getdp(mtd::mVector&, const...
|
by: Alex Zhitlenok |
last post by:
Hi,
My question is how to resolve in C# ambiguous overloaded operators?
Let say, I have two unrelated classes A and B, each one implements
overloaded operator + with the first parameter of type...
|
by: Michi Henning |
last post by:
Hi,
the following code produces an error on the second-last line:
Interface Left
Sub op()
End Interface
Interface Right
Sub op(ByVal i As Integer)
|
by: Arpan |
last post by:
The following code exists in a class file named "Users.vb":
Namespace Users
Public Class UserDetails
Public FirstName As String
Public LastName As String
Public UserName As String
Public...
|
by: Chameleon |
last post by:
Can anyone explain me why the code below produce (with mingw-g++) the
following error message:
---------------------------------------------------------------
main10.cpp: In function `int main()':...
|
by: pvl_google |
last post by:
Hi,
I'm trying to extend an STL class with additional iterator
functionality. In the simplified example below I added an extra
iterator class with a dereferencing operator. This operator...
|
by: xtrigger303 |
last post by:
Hi to all,
I'm working on a smart pointer implementation and I'm trying to get
automatic type conversion between different pointer types. I stumbled
upon something weird (at least for me) I...
|
by: sebastian |
last post by:
I've simplified the situation quite a bit, but essentially I have
something like this:
struct foo
{ };
void
bar( foo const & lhs, foo const & rhs )
|
by: mathieu |
last post by:
Could someone please tell me what is wrong with the following -ugly-
piece of c++ code. Why when I explicititely set the template parameter
my gcc compiler start getting confused:
bla.cxx: In...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |