[Search for users]
[Overall Top Noters]
[List of all Conferences]
[Download this site]
Title: | C++ |
Notice: | Read 1.* and use keywords (e.g. SHOW KEY/FULL KIT_CXX_VAX_VMS) |
Moderator: | DECCXX::AMARTIN |
|
Created: | Fri Nov 06 1987 |
Last Modified: | Thu Jun 05 1997 |
Last Successful Update: | Fri Jun 06 1997 |
Number of topics: | 3604 |
Total number of notes: | 18242 |
This function object example is straight from Musser &Saini, page 174:
#include <string>
#include <iostream.h>
class intGreater {
public:
bool operator()(int x, int y) const { return x > y; }
};
int main(int argc, char **argv)
{
int x[10], i;
for( i=0; i<10; i++ )
x[i] = 20 * (4-i) - (i/2);
cerr << "int array is : " << endl;
for( i = 0; i < 10; i++ )
cerr << i << ": " << x[i] << endl;
sort(&x[0], &x[10], intGreater());
cerr << "int array is : " << endl;
for( i = 0; i < 10; i++ )
cerr << i << ": " << x[i] << endl;
}
This fails to compile:
cxx: Error: ./cxx_repository/sort__XPiPi10intGreater.cxx, line 2: Ill-formed
parameter type list.
void static __dummy_ (int *p1, int *p2, intGreater p3)
----------------------------------------^
Any idea why?
Paul
[Posted by WWW Notes gateway]
T.R | Title | User | Personal Name | Date | Lines |
---|
3585.1 | | SPECXN::DERAMO | Dan D'Eramo | Thu May 22 1997 11:16 | 14 |
| During linking it is realized that the instantiation file
./cxx_repository/sort__XPiPi10intGreater.cxx needs to be
compiled. That file uses intGreater but has no definition of
intGreater. That's because the template instantiation process
expects class intGreater to be declared in one of the header
files #include'd by the original source file.
If you move the declaration of class intGreater to a header
file which is included by the main .cxx program then the
default template instantiation process should work. Also,
there is most likely a compiler command line qualifier to
force the instantiation and using that should work too.
Dan
|
3585.2 | stl function objects, templates | NNTPD::"[email protected]" | Paul Doyle | Mon May 26 1997 05:23 | 9 |
| Dan,
putting the intGreater declaration into a header file fixed the
problem for me - thanks for your help, and for the clear explanation
of what was going wrong.
Paul
[Posted by WWW Notes gateway]
|