Hi All,
I want to use scrJ_minus_O as the function to fill in the array "a" in
population_decomposition. But the g++ compiler always says the line "
pop_dec(scrJ_minus_O<double>(.5));" is wrong.
main.cc: In function `int main(int, char **)':
main.cc:39: no matching function for call to `pop_dec
(scrJ_minus_O<double>)'
Would you please tell me how I should change line 39? Thanks!
Best wishes,
Peng
#include <iostream>
#include <functional>
#include <cmath>
template <class _Tp>
class scrJ_minus_O : public binary_function<_Tp, _Tp, _Tp>{
public:
scrJ_minus_O(_Tp sigma) : _sigma(sigma) {};
_Tp operator()(const _Tp f, const _Tp g){
if((f * f + g * g) < _sigma * _sigma)
return 1. / (M_PI * _sigma * _sigma);
else
return 0.;
}
private:
_Tp _sigma;
};
template <class _Tp, class _Generator>
class population_decomposition {
public:
population_decomposition(const _Generator& generator) :
_generator(generator) {
for(int i = 0; i < 10; i ++){
a[i] = _generator(.1 * i, .1 * i);
}
};
_Tp a[10];
private:
_Generator _generator;
};
template <class _Tp, class _Generator>
inline population_decomposition<_Tp, _Generator>
pop_dec(const _Generator& generator){
return population_decomposition<_Tp,_Generator>(generator );
}
main(int argc, char *argv[]){
pop_dec(scrJ_minus_O<double>(.5));
} 5 1478
<Pe*******@gmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com Hi All,
I want to use scrJ_minus_O as the function to fill in the array "a" in population_decomposition. But the g++ compiler always says the line " pop_dec(scrJ_minus_O<double>(.5));" is wrong.
[snip]
template <class _Tp, class _Generator> inline population_decomposition<_Tp, _Generator> pop_dec(const _Generator& generator){ return population_decomposition<_Tp,_Generator>(generator ); }
main(int argc, char *argv[]){ pop_dec(scrJ_minus_O<double>(.5)); }
How is the compiler to figure out the template argument for _Tp? Try
pop_dec<double>(scrJ_minus_O<double>(.5));
(you have also omitted the return type int from main).
--
John Carson
On Sat, 16 Apr 2005 14:42:49 +1000, "John Carson"
<jc****************@netspace.net.au> wrote: <Pe*******@gmail.com> wrote in message news:11**********************@l41g2000cwc.googleg roups.com Hi All,
I want to use scrJ_minus_O as the function to fill in the array "a" in population_decomposition. But the g++ compiler always says the line " pop_dec(scrJ_minus_O<double>(.5));" is wrong.
[snip]
template <class _Tp, class _Generator> inline population_decomposition<_Tp, _Generator> pop_dec(const _Generator& generator){ return population_decomposition<_Tp,_Generator>(generator ); }
main(int argc, char *argv[]){ pop_dec(scrJ_minus_O<double>(.5)); }
How is the compiler to figure out the template argument for _Tp? Try
pop_dec<double>(scrJ_minus_O<double>(.5));
(you have also omitted the return type int from main).
The thing that I don't understand is why we could only specify only
one type(double) for pop_dec while it has two types(_Tp, _Generator)?
Peng
"Peng Yu" <pe*******@gmail.com> wrote in message
news:bv********************************@4ax.com On Sat, 16 Apr 2005 14:42:49 +1000, "John Carson" <jc****************@netspace.net.au> wrote:
<Pe*******@gmail.com> wrote in message news:11**********************@l41g2000cwc.googlegr oups.com template <class _Tp, class _Generator> inline population_decomposition<_Tp, _Generator> pop_dec(const _Generator& generator){ return population_decomposition<_Tp,_Generator>(generator ); }
main(int argc, char *argv[]){ pop_dec(scrJ_minus_O<double>(.5)); }
How is the compiler to figure out the template argument for _Tp? Try
pop_dec<double>(scrJ_minus_O<double>(.5));
(you have also omitted the return type int from main).
The thing that I don't understand is why we could only specify only one type(double) for pop_dec while it has two types(_Tp, _Generator)?
You can specify both types if you want. However, you have the option to omit
those template arguments that the compiler can deduce itself from the
function's arguments. Note, however, that only trailing template arguments
can be omitted. If, say, the compiler can deduce the first argument but not
the second, then you would have to supply both (this is the same as the rule
for template arguments that have defaults --- once again, you can only omit
trailing arguments).
--
John Carson
I'm not very sure how to specify the type of the function
object(_Generator). Would you please tell me how to specify it
explicitly in the above example?
Thanks,
Peng
<Pe*******@gmail.com> wrote in message
news:11********************@g14g2000cwa.googlegrou ps.com I'm not very sure how to specify the type of the function object(_Generator). Would you please tell me how to specify it explicitly in the above example?
pop_dec as defined in your code takes an argument of type reference to
_Generator. When you call pop_dec, you use the following code:
pop_dec(scrJ_minus_O<double>(.5));
This means that _Generator is the type of scrJ_minus_O<double>(.5).
scrJ_minus_O<double>(.5) calls the constructor for scrJ_minus_O<double> and
thus creates a temporary object of type scrJ_minus_O<double>. _Generator is
therefore scrJ_minus_O<double>.
A fully explicit call of pop_dec would be:
pop_dec<double, scrJ_minus_O<double> >(scrJ_minus_O<double>(.5));
--
John Carson This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Phil Powell |
last post by:
if (is_array($_POST)) {
foreach ($this->getAssocSectionsObjArray($key, $dbAP) as
$obj) {
print_r($obj); print_r(" in array? ");
print_r(in_array($obj, $result)); print_r("<P>");
if...
|
by: The Roys |
last post by:
Hi
Im doing something wrong in quitting the Word.Application in my VB program.
I have
General Declarations
Dim AppWord As Word.Application
Form_Load()
Set AppWord =...
|
by: Jonathan Fine |
last post by:
Giudo has suggested adding optional static typing to Python.
(I hope suggested is the correct word.)
http://www.artima.com/weblogs/viewpost.jsp?thread=85551
An example of the syntax he proposes...
|
by: xuatla |
last post by:
Hi,
I encountered the following compile error of c++ and hope to get your help.
test2.cpp: In member function `CTest CTest::operator+=(CTest&)':
test2.cpp:79: error: no match for 'operator='...
|
by: Tim Eliot |
last post by:
Just wondering if anyone has hit the following issue and how you might
have sorted it out.
I am using the command:
DoCmd.TransferText acExportMerge, , stDataSource, stFileName, True
after...
|
by: Ernst Berg |
last post by:
Thankfully there is a C language group!
Hello!
I am a hobyist who is rediscovering writing C programs on Linux. I
use GCC and I am at a loss as to why the compile fails to find the...
|
by: ANaiveProgrammer |
last post by:
Hi all
I have been trying to send a struct over socket. I tried to assign the
values of struct
to unsigned char array. I have attached both .c files at the bottom.
'Client.c' takes a
struct,...
|
by: dfetrow410 |
last post by:
Anyone have some code that will do this?
Dave
|
by: KitKat |
last post by:
I need to get this to go to each folders: Cam 1, Cam 2, Cam 4, Cam 6, Cam 7,
and Cam 8. Well it does that but it also needs to change the file name to
the same folder where the file is being...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |