Hi,
I couldn't see what is wrong with the following program. Would you
please help me?
Thanks,
Peng
g++-3.4 -MM -g main.cc .dep
g++-3.4 -g -c -o main.o main.cc
main.cc: In function `int main()':
main.cc:26: error: cannot convert `double' to `function<int(*)()' for
argument `1' to `const interpolator2d<function<int
inter_f(function<int(*)())'
make: *** [main.o] Error 1
#include <functional>
template <typename F>
class interpolator2d {
public:
interpolator2d(const F &f) : _f(f) {
}
typename F::result_type operator()(double x, double y) const {
return _f(x, y);
}
private:
F _f;
};
template <typename T>
struct function : public std::binary_function<T, T, double{
double operator()(T x, T y) const {
return - (x * x + y * y);
}
};
int main() {
const interpolator2d<function<int inter_f(function<int>());
double x = 0;
double y = 0;
inter_f(1.1, 1.1);
} 6 1431 Pe*******@gmail.com wrote:
Hi,
I couldn't see what is wrong with the following program. Would you
please help me?
Thanks,
Peng
g++-3.4 -MM -g main.cc .dep
g++-3.4 -g -c -o main.o main.cc
main.cc: In function `int main()':
main.cc:26: error: cannot convert `double' to `function<int(*)()'
for argument `1' to `const interpolator2d<function<int
inter_f(function<int(*)())'
make: *** [main.o] Error 1
#include <functional>
template <typename F>
class interpolator2d {
public:
interpolator2d(const F &f) : _f(f) {
}
typename F::result_type operator()(double x, double y) const {
return _f(x, y);
}
private:
F _f;
};
template <typename T>
struct function : public std::binary_function<T, T, double{
double operator()(T x, T y) const {
return - (x * x + y * y);
}
};
int main() {
const interpolator2d<function<int inter_f(function<int>());
I just wonder how many times people will be posting questions after
walking into this?..
Repeat after me: the statement above is a declaration of a FUNCTION,
not an object as you intended. This is the same as if you wrote
int a(double());
intending to construct an integer from a default-initialised double.
It's a FUNCTION declaration.
To fix it surround each argument (the only argument in your case)
with an extra set of parentheses. Should be
... inter_f((function<int>()));
double x = 0;
double y = 0;
inter_f(1.1, 1.1);
}
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask Pe*******@gmail.com wrote:
Hi,
I couldn't see what is wrong with the following program. Would you
please help me?
Thanks,
Peng
g++-3.4 -MM -g main.cc .dep
g++-3.4 -g -c -o main.o main.cc
main.cc: In function `int main()':
main.cc:26: error: cannot convert `double' to `function<int(*)()' for
argument `1' to `const interpolator2d<function<int
inter_f(function<int(*)())'
make: *** [main.o] Error 1
#include <functional>
template <typename F>
class interpolator2d {
public:
interpolator2d(const F &f) : _f(f) {
}
typename F::result_type operator()(double x, double y) const {
return _f(x, y);
}
private:
F _f;
};
template <typename T>
struct function : public std::binary_function<T, T, double{
double operator()(T x, T y) const {
return - (x * x + y * y);
}
};
int main() {
const interpolator2d<function<int inter_f(function<int>());
This is parsed as a function declaration. Make that:
const interpolator2d<function<int inter_f((function<int>()));
double x = 0;
double y = 0;
inter_f(1.1, 1.1);
}
Best
Kai-Uwe Bux
On Oct 28, 6:05 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
PengYu...@gmail.com wrote:
Hi,
I couldn't see what is wrong with the following program. Would you
please help me?
Thanks,
Peng
g++-3.4 -MM -g main.cc .dep
g++-3.4 -g -c -o main.o main.cc
main.cc: In function `int main()':
main.cc:26: error: cannot convert `double' to `function<int(*)()'
for argument `1' to `const interpolator2d<function<int
inter_f(function<int(*)())'
make: *** [main.o] Error 1
#include <functional>
template <typename F>
class interpolator2d {
public:
interpolator2d(const F &f) : _f(f) {
}
typename F::result_type operator()(double x, double y) const {
return _f(x, y);
}
private:
F _f;
};
template <typename T>
struct function : public std::binary_function<T, T, double{
double operator()(T x, T y) const {
return - (x * x + y * y);
}
};
int main() {
const interpolator2d<function<int inter_f(function<int>());I just wonder how many times people will be posting questions after
walking into this?..
Repeat after me: the statement above is a declaration of a FUNCTION,
not an object as you intended. This is the same as if you wrote
int a(double());
intending to construct an integer from a default-initialised double.
It's a FUNCTION declaration.
To fix it surround each argument (the only argument in your case)
with an extra set of parentheses. Should be
... inter_f((function<int>()));
double x = 0;
double y = 0;
inter_f(1.1, 1.1);
}V
main.cc:26: error: cannot convert `double' to `function<int(*)()' for
argument `1' to `const interpolator2d<function<int
I still don't understand the error message. Where is the `double'? Does
`function<int(*)()' mean a function? Can I declare function in
arguments of a class constructor?
Thanks,
Peng Pe*******@gmail.com wrote:
On Oct 28, 6:05 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>PengYu...@gmail.com wrote:
>>Hi,
>>I couldn't see what is wrong with the following program. Would you please help me?
>>Thanks, Peng
>>g++-3.4 -MM -g main.cc .dep g++-3.4 -g -c -o main.o main.cc main.cc: In function `int main()': main.cc:26: error: cannot convert `double' to `function<int(*)()' for argument `1' to `const interpolator2d<function<int inter_f(function<int(*)())' make: *** [main.o] Error 1
>>#include <functional>
>>template <typename F> class interpolator2d { public: interpolator2d(const F &f) : _f(f) { } typename F::result_type operator()(double x, double y) const { return _f(x, y); } private: F _f; };
>>template <typename T> struct function : public std::binary_function<T, T, double{ double operator()(T x, T y) const { return - (x * x + y * y); } };
>>int main() { const interpolator2d<function<int inter_f(function<int>());I just wonder how many times people will be posting questions after walking into this?..
Repeat after me: the statement above is a declaration of a FUNCTION, not an object as you intended. This is the same as if you wrote
int a(double());
intending to construct an integer from a default-initialised double. It's a FUNCTION declaration.
To fix it surround each argument (the only argument in your case) with an extra set of parentheses. Should be
... inter_f((function<int>()));
>> double x = 0; double y = 0; inter_f(1.1, 1.1); }V
main.cc:26: error: cannot convert `double' to `function<int(*)()'
for argument `1' to `const interpolator2d<function<int
I still don't understand the error message. Where is the `double'?
1.1 is the double.
Does `function<int(*)()' mean a function?
Your 'inter_f' *function* takes one argument, a pointer to a function.
Can I declare function in
arguments of a class constructor?
Not sure what you're asking here, sorry. Please rephrase.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
<Pe*******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com
On Oct 28, 6:05 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>PengYu...@gmail.com wrote:
>>Hi,
>>I couldn't see what is wrong with the following program. Would you please help me?
>>Thanks, Peng
>>g++-3.4 -MM -g main.cc .dep g++-3.4 -g -c -o main.o main.cc main.cc: In function `int main()': main.cc:26: error: cannot convert `double' to `function<int(*)()' for argument `1' to `const interpolator2d<function<int inter_f(function<int(*)())' make: *** [main.o] Error 1
>>#include <functional>
>>template <typename F> class interpolator2d { public: interpolator2d(const F &f) : _f(f) { } typename F::result_type operator()(double x, double y) const { return _f(x, y); } private: F _f; };
>>template <typename T> struct function : public std::binary_function<T, T, double{ double operator()(T x, T y) const { return - (x * x + y * y); } };
>>int main() { const interpolator2d<function<int inter_f(function<int>());I just wonder how many times people will be posting questions after walking into this?..
Repeat after me: the statement above is a declaration of a FUNCTION, not an object as you intended. This is the same as if you wrote
int a(double());
intending to construct an integer from a default-initialised double. It's a FUNCTION declaration.
To fix it surround each argument (the only argument in your case) with an extra set of parentheses. Should be
... inter_f((function<int>()));
>> double x = 0; double y = 0; inter_f(1.1, 1.1); }V
main.cc:26: error: cannot convert `double' to `function<int(*)()'
for argument `1' to `const interpolator2d<function<int
I still don't understand the error message. Where is the `double'?
Does `function<int(*)()' mean a function? Can I declare function in
arguments of a class constructor?
The point is that the compiler is not interpreting your code as a call to
the class constructor at all.
const interpolator2d<function<int inter_f(function<int>());
is interpreted as the declaration of a function called inter_f which takes
an argument of type function<intand returns an object of type const
interpolator2d<function<int.
--
John Carson
Kai-Uwe Bux wrote:
Pe*******@gmail.com wrote:
>>Hi,
I couldn't see what is wrong with the following program. Would you please help me?
Thanks, Peng
g++-3.4 -MM -g main.cc .dep g++-3.4 -g -c -o main.o main.cc main.cc: In function `int main()': main.cc:26: error: cannot convert `double' to `function<int(*)()' for argument `1' to `const interpolator2d<function<int inter_f(function<int(*)())' make: *** [main.o] Error 1
#include <functional>
template <typename F> class interpolator2d { public: interpolator2d(const F &f) : _f(f) { } typename F::result_type operator()(double x, double y) const { return _f(x, y); } private: F _f; };
template <typename T> struct function : public std::binary_function<T, T, double{ double operator()(T x, T y) const { return - (x * x + y * y); } };
int main() { const interpolator2d<function<int inter_f(function<int>());
This is parsed as a function declaration. Make that:
const interpolator2d<function<int inter_f((function<int>()));
> double x = 0; double y = 0; inter_f(1.1, 1.1); }
Best
Kai-Uwe Bux
still does not work. that line needs to be:
const interpolator2d<function<double inter_f((function<double>()));
or not to use double numbers in the last line This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Brandon J. Van Every |
last post by:
What's better about Ruby than Python? I'm sure there's something. What is
it?
This is not a troll. I'm language shopping and I want people's answers. I
don't know beans about Ruby or have...
|
by: marco |
last post by:
the problem:
I use a typedef inside a class template, than I use this type
(dim_v<N1>::Type) to define the argument of a template function f
but when I call this function from main, the compiler...
|
by: PengYu.UT |
last post by:
Hi,
It seems that the line with "//no error" and "//error" are the same.
However, the second one give an error.
I'm using g++-3.3.
The error message was:
g++-3.3 -g -c -o main.o main.cc...
|
by: Micha |
last post by:
Hello there,
I think I've run into some classic c++ pitfall and maybe some of
you guys can help me out.
For my project I will need to use matrices and vectors and so I
decided to implement them...
|
by: PengYu.UT |
last post by:
Hi,
I run into error with the following program. Would you please help me?
Best wishes,
Peng
struct tag1{};
struct tag2{};
|
by: Oliver Brausch |
last post by:
Hello,
have you ever heard about this MS-visual c compiler bug?
look at the small prog:
static int x=0;
int bit32() {
return ++x;
}
|
by: Protoman |
last post by:
Could you tell me what's wrong with this program, it doesn't compile:
#include <iostream>
#include <cstdlib>
using namespace std;
class Everything
{
public:
static Everything* Instance()
|
by: mosfet |
last post by:
HI,
when trying to compile an embedded version of STL called ustl on win32
platform I get the following error :
/// Returns the minimum of \p a and \p b
template <typename T1, typename T2>...
|
by: DaveJ |
last post by:
Recently I was working on a project where I came across an issue where
the program cored and reported "free(): invalid pointer".
I found a resolution for this, but don't fully understand why the...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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: 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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |