![]() |
functors in C++
hi i was going through Functor tutorial on net which had the following example
Code:
class TFunctorCode:
class TClassA{Now i tried to replace main() with a class Code:
class testCode:
TSpecificFunctor<TClassA> specFuncA(&objA, &TClassA::Display); |
Re: functors in C++
You always have to have a main function in C++; it's the starting point for your program.
|
Re: functors in C++
Quote:
I tried to compile this piece of code with -c option |
Re: functors in C++
OK. What does "This is not possible" mean? Do you get an error?
If so, what is that error? If not, please explain why you think it is not possible. |
Re: functors in C++
Sorry for the confusion. I will add it properly this time .
This is my hdr file (hdr.h) file. Code:
class TFunctor[code] Code:
#include "hdr.h"I get this error while compiling Code:
[root@localhost example]# g++ -c hdr.cpp |
Re: functors in C++
OK, so it looks like you've taken the code from main() and are trying to use it as a class definition.
This won't work; you need to write function code in functions, not in class definitions. One way if the code must go in a class definition is to have a member function that contains the code from main; that should work OK. Code:
class test { |
Re: functors in C++
hi now it compiles. I was under the impression that
Code:
TSpecificFunctor<TClassA> specFuncA(&objA, &TClassA::Display); |
Re: functors in C++
thanks for replying xpi0t0s now it works for me
|
| All times are GMT +5.5. The time now is 12:51. |