473,503 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Functor Compilation Error

I'm getting an error that I can't seem to resolve. When I compile the
Functor related logic in a test program, the files compile and execute
properly (see Listing #1).

However, when I incorporate the same logic within my simulation, the
class that implements the functor logic has problems compiling. I get
the following errors:
-- Building myTest.cpp --
In file included from myTest.cpp:52:
.../tstDir/myFunctor.h:19: error: expected unqualified-id before '*'
token
.../tstDir/myFunctor.h:19: error: expected `)' before '*' token
.../tstDir/myFunctor.h:19: error: expected `,' or `...' before '*'
token
.../tstDir/myFunctor.h:19: error: `TSpecificFunctor' declared as
function returning a function
.../tstDir/myFunctor.h:19: error: `<anonymous>' has incomplete type
.../tstDir/myFunctor.h:19: error: invalid use of `void'
.../tstDir/myFunctor.h:19: error: expected `;' before ')' token
myTest.cpp: In member function `virtual void
tst::myTest::Initialize()':
myTest.cpp:527: error: no matching function for call to
`tst::TSpecificFunctor<tst::myScats>::TSpecificFun ctor(tst::myScats*,
void (tst::myScats::*)())'
.../tstDir/myFunctor.h:14: note: candidates are:
tst::TSpecificFunctor<tst::myScats>::TSpecificFunc tor(const
tst::TSpecificFunctor<tst::myScats>&)

Listing #2 provides the functor implementation as used in my
simulation. Can anyone tell me what is causing the compilation error
and how to possibly resolve it?

LISTING #2 (code in simulation)

In myTest.cpp:

#include "ScatFunctor.h"
#include "myScats.h"
#include "myFunctor.h"

void myTest::Initialize()
{
using namespace tst;

myScats objB;

TSpecificFunctor<myScatsspecFunc( &objB, &myScats::Initialize);

myFunctor* funcTable[] = { &specFunc };

funcTable[0]->Call();
}
In myFunctor.h:

#ifndef myFunctor_H
#define myFunctor_H

#include "tst_config.h"

#include "ScatFunctor.h"

BEGIN_TST_NAMESPACE
template <class TClassclass TSpecificFunctor : public TFunctor
{
public:

// Constructor - takes pointer to an object and pointer to
// a member function and stores them in two private variables
TSpecificFunctor(TClass* _pt2Object, void(TClass::_*fpt) ())
{ pt2Object = _pt2Object; fpt = _fpt; };

// override function "call" in base class
virtual void Call()
{ (*pt2Object.*fpt) (); };

private:

void (TClass::*fpt) ();
TClass* pt2Object;
};

END_TST_NAMESPACE

#endif

In ScatFunctor.h:

#ifndef ScatFunctor_H
#define ScatFunctor_H

#include "tst_config.h"

BEGIN_TST_NAMESPACE

class TFunctor
{
public:

virtual void Call(); // call using function
};

END_TST_NAMESPACE

#endif
In myScats.h:

#ifndef myScats_H
#define myScats_H

#include "tst_config.h"

BEGIN_TST_NAMESPACE

class myScats
{
public:

// Constructor/Destructor
myScats() {};
virtual ~myScats();

void Initialize() {"In Scats Initialize"};

protected:

private:
};

END_TST_NAMESPACE

#endif // End of Listing #2

LISTING #1 (stand-alone test program)

In BaseFunctor.cpp:
#include "BaseFunctor.h"
#include "DerivedFunctor.h"
#include "sea.h"

int main (int argc, char* argv[])
{
sea objB;

// instantiate DerivedFunctor objects ...
// functor encapsulating pointer to object and to a member of
class sea
TSpecificFunctor<seaspecFuncSea(&objB, &sea::Display);

// array with pointers to the Base class (TFunctor) and initialize
it
TFunctor *vT = { &specFuncSea };

vT->Call();

return 0;
}
In BaseFunctor.h:

#ifndef BaseFunctor_H
#define BaseFunctor_H

// abstract base class

class TFunctor
{
public:

// Derived classes will use a pointer to an object and
// a pointer to a member function to make the function call
virtual void Call()=0; //call using provided function name
};

#endif
In DerivedFunctor.h:

#ifndef TSpecificFunctor_H
#define TSpecificFunctor_H

#include "BaseFunctor.h"
template <class TClassclass TSpecificFunctor : public TFunctor
{
public:

// Constructor - takes pointer to an object and pointer to
// a member function and stores them in two private variables

TSpecificFunctor(TClass* _pt2Object, void(TClass::*_fpt) ())
{ pt2Object = _pt2Object; fpt = _fpt; };

// override function "Call" in base class
virtual void Call() // executes member function
{ (*pt2Object.*fpt) (); };

private:

void (TClass::*fpt) (); // pointer to a member function
TClass* pt2Object; // pointer to an object
};

#endif

In Sea.h:

#ifndef sea_H
#define sea_H

#include <iostream>

using namespace std;

class sea
{
public:

sea() {};

// Sea's Functions
void Display() { cout << "In Sea Display" << endl; };

};

#endif

The above (LISTING #1) is compiled with the following script and
the resulting binary executes properly:

#/bin/sh

echo compiling C++ using -ansi -pedantic-errors -Wall -fPIC -g
g++ -ansi -pedantic-errors -Wall -Wno-deprecated -fPIC -g $1 $2 $3
Any help regarding some possible solutions for the compilation errors
would be greatly appreciated!

Danny

Nov 4 '07 #1
1 2792
On Nov 3, 11:27 pm, BSand0...@msn.com wrote:
I'm getting an error that I can't seem to resolve. When I compile theFunctorrelated logic in a test program, the files compile and execute
properly (see Listing #1).

However, when I incorporate the same logic within my simulation, the
class that implements thefunctorlogic has problems compiling. I get
the following errors:

-- Building myTest.cpp --
In file included from myTest.cpp:52:
../tstDir/myFunctor.h:19: error: expected unqualified-id before '*'
token
../tstDir/myFunctor.h:19: error: expected `)' before '*' token
../tstDir/myFunctor.h:19: error: expected `,' or `...' before '*'
token
../tstDir/myFunctor.h:19: error: `TSpecificFunctor' declared as
function returning a function
../tstDir/myFunctor.h:19: error: `<anonymous>' has incomplete type
../tstDir/myFunctor.h:19: error: invalid use of `void'
../tstDir/myFunctor.h:19: error: expected `;' before ')' token
myTest.cpp: In member function `virtual void
tst::myTest::Initialize()':
myTest.cpp:527: error: no matching function for call to
`tst::TSpecificFunctor<tst::myScats>::TSpecificFun ctor(tst::myScats*,
void (tst::myScats::*)())'
../tstDir/myFunctor.h:14: note: candidates are:
tst::TSpecificFunctor<tst::myScats>::TSpecificFunc tor(const
tst::TSpecificFunctor<tst::myScats>&)

Listing #2 provides thefunctorimplementation as used in my
simulation. Can anyone tell me what is causing the compilation error
and how to possibly resolve it?

LISTING #2 (code in simulation)

In myTest.cpp:

#include "ScatFunctor.h"
#include "myScats.h"
#include "myFunctor.h"

void myTest::Initialize()
{
using namespace tst;

myScats objB;

TSpecificFunctor<myScatsspecFunc( &objB, &myScats::Initialize);

myFunctor* funcTable[] = { &specFunc };

funcTable[0]->Call();

}

In myFunctor.h:

#ifndef myFunctor_H
#define myFunctor_H

#include "tst_config.h"

#include "ScatFunctor.h"

BEGIN_TST_NAMESPACE

template <class TClassclass TSpecificFunctor : public TFunctor
{
public:

// Constructor - takes pointer to an object and pointer to
// a member function and stores them in two private variables
TSpecificFunctor(TClass* _pt2Object, void(TClass::_*fpt) ())
{ pt2Object = _pt2Object; fpt = _fpt; };

// override function "call" in base class
virtual void Call()
{ (*pt2Object.*fpt) (); };

private:

void (TClass::*fpt) ();
TClass* pt2Object;

};

END_TST_NAMESPACE

#endif

In ScatFunctor.h:

#ifndef ScatFunctor_H
#define ScatFunctor_H

#include "tst_config.h"

BEGIN_TST_NAMESPACE

class TFunctor
{
public:

virtual void Call(); // call using function

};

END_TST_NAMESPACE

#endif

In myScats.h:

#ifndef myScats_H
#define myScats_H

#include "tst_config.h"

BEGIN_TST_NAMESPACE

class myScats
{
public:

// Constructor/Destructor
myScats() {};
virtual ~myScats();

void Initialize() {"In Scats Initialize"};

protected:

private:

};

END_TST_NAMESPACE

#endif // End of Listing #2

LISTING #1 (stand-alone test program)

In BaseFunctor.cpp:

#include "BaseFunctor.h"
#include "DerivedFunctor.h"
#include "sea.h"

int main (int argc, char* argv[])
{
sea objB;

// instantiate DerivedFunctor objects ...
//functorencapsulating pointer to object and to a member of
class sea
TSpecificFunctor<seaspecFuncSea(&objB, &sea::Display);

// array with pointers to the Base class (TFunctor) and initialize
it
TFunctor *vT = { &specFuncSea };

vT->Call();

return 0;

}

In BaseFunctor.h:

#ifndef BaseFunctor_H
#define BaseFunctor_H

// abstract base class

class TFunctor
{
public:

// Derived classes will use a pointer to an object and
// a pointer to a member function to make the function call
virtual void Call()=0; //call using provided function name

};

#endif

In DerivedFunctor.h:

#ifndef TSpecificFunctor_H
#define TSpecificFunctor_H

#include "BaseFunctor.h"

template <class TClassclass TSpecificFunctor : public TFunctor
{
public:

// Constructor - takes pointer to an object and pointer to
// a member function and stores them in two private variables

TSpecificFunctor(TClass* _pt2Object, void(TClass::*_fpt) ())
{ pt2Object = _pt2Object; fpt = _fpt; };

// override function "Call" in base class
virtual void Call() // executes member function
{ (*pt2Object.*fpt) (); };

private:

void (TClass::*fpt) (); // pointer to a member function
TClass* pt2Object; // pointer to an object

};

#endif

In Sea.h:

#ifndef sea_H
#define sea_H

#include <iostream>

using namespace std;

class sea
{
public:

sea() {};

// Sea's Functions
void Display() { cout << "In Sea Display" << endl; };

};

#endif

The above (LISTING #1) is compiled with the following script and
the resulting binary executes properly:

#/bin/sh

echo compiling C++ using -ansi -pedantic-errors -Wall -fPIC -g
g++ -ansi -pedantic-errors -Wall -Wno-deprecated -fPIC -g $1 $2 $3

Any help regarding some possible solutions for the compilation errors
would be greatly appreciated!

Danny
Thanks Alf!! Your suggestions / tips worked great! However, I now
have a secondary problem if you or anyone else could help me with. I
have the following code:

#ifndef MYFUNCTOR_H
#define MYFUNCTOR_H

#include "struct1.h"
#include "struct2.h"

class MyFunctor
{
public:

// No arg list
virtual void Call()=0; // call using function

// For multi args
virtual void Call_m(struct1*, struct2*, int, double)=0;
};
#endif
#ifndef TSTFUNCTOR_H
#define TSTFUNCTOR_H

#include "MyFunctor.h"

template <class TClassclass TSpecificFunctor : public MyFunctor
{
public:

// Constructor - takes pointer to an object and pointer to
// a member function and stores them in two private variables

// no arg list
TSpecificFunctor( TClass* _pt2Object, void(TClass::*tfpt) ())
{ pt2Object = _pt2Object; fpt = tfpt; };

// For Multi Args
TSpecificFunctor( TClass* _pt2Object, void(TClass::*tfpt)
(struct1*, struct2*,
int, double) )
{ pt2Object = _pt2Object; fpt = tfpt; };

// override function "call" in base class
// no arg list
virtual void Call()
{ (*pt2Object.*fpt) (); };

// For Multi Args
virtual void Call_m(struct1* bkgnd, struct2* geo, int val1,
double val2)
{ (*pt2Object.*fpt) (bkgnd, geo, val1, val2); };
private:

// For No Arguments
void (TClass::*fpt) ();

// For Multi Args
void (TClass::*fpt) (struct1*, struct2*, int, double);

TClass* pt2Object;
};
#endif

In Source Code (MyCode.cpp):

Land objLand;

TSpecificFunctor<LandspecFuncLand_0(&objLand, &Land::init_test);
TSpecificFunctor<LandspecFuncLand_1(&objLand, &LandS::init_test3);

ScatFunctor *funcTable[] = { &specFuncLand_0, &specFuncLand_1 };

// call test function (no arguments)
funcTable[0]->Call();

// call registered multi args function
funcTable[1]->Call_m(str1, str2, Val1, Val2);
When I compile and just use one of the constructors (e.g. the multi
argument case), all works well. However, when I add the no argument
case, I get the following compilation errors:

Errors during compilation:

TstFunctor.h:78: error: declaration of `void
(TClass::*TSpecificFunctor<TClass>::fpt)()'
TstFunctor.h:68: error: conflicts with previous declaration `void
(TClass::*TSpecificFunctor<TClass>::fpt)(struct1*, struct2*, int,
double)'
TstFunctor.h: In constructor
`TSpecificFunctor<TClass>::TSpecificFunctor(TClass *, void (TClass::*)
()) [with TClass = Land]':
MyCode.cpp:258: instantiated from here
TstFunctor.h:42: error: cannot convert `void (Land::*)()' to `void
(Land::*)(struct1*, struct2*, int, double)' in assignment
TstFunctor.h: In member function `void
TSpecificFunctor<TClass>::Call() [with TClass = Land]':
MyCode.cpp:2287: instantiated from here
TstFunctor.h:63: error: too few arguments to function
make[1]: *** [Mycode.o] Error 1
Is there a way to setup my classes to handle various argument lengths
for the functions I need to use (e.g. init_test, init_test3)? I
thought I could over-ride the constructors in TstFunctor.h, but either
I can't, or I'm not doing it correctly.

Thanks for any help / tips that can be provided.

Danny

Nov 8 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2213
by: Joachim | last post by:
I made some project changes (which seems it doesn't help if I undo) which have created compilation error: " Server Error in '/PCSWebApp1' Application....
2
1792
by: James Zhuo | last post by:
Hi all I've been getting the following compilation error. I should explain the background of the project that i am taking over. This is a project that has been developed by someone else a while...
0
1445
by: James Zhuo | last post by:
hi all I changed the name of the class LoginPage to a different name "LoginPageOne" But the same error gets generated with the Wiliam.Request.LoginPageOne. That pretty much leaves me clueless...
0
1507
by: Jie | last post by:
Does anyone know why I keep having the following error. I have to rebuild the solution every time I run it in design mode. thanks jie Server Error in '/ReapPortal' Application....
0
1264
by: John | last post by:
Hi, I've just rolled out a new version of an ASP.NET application. It runs fine on development and training servers, but on production get the following error when trying to access a page: ...
2
1912
by: VB Programmer | last post by:
I created a ASP.NET app locally and it works great. Uploaded it to my server and I get this error when trying to view a page. Any ideas? Server Error in '/earlyalert3' Application....
2
6915
by: Kevin R. | last post by:
I have been ignoring this problem for a few weeks now, but it's becoming a bit annoying not to mention unproductive. Here it goes: I compile my project with no errors. Then after I debug/run it,...
6
2868
by: Plat | last post by:
I've Googled this for a while, to no avail. Hopefully someone can help me. Maybe I'm using the wrong terminology. Here's the scoop! Let's say I've got a simple *.ASPX page that has a syntax...
0
1725
by: Stimp | last post by:
I've created an aspx page called HistoryManage.aspx. The page works fine on my local machine but when I load it off the web I get the following strange error... Compilation Error...
0
7201
marktang
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,...
0
7083
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...
0
7328
jinu1996
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...
1
6988
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...
0
7456
tracyyun
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...
0
5578
agi2029
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,...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1510
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
379
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.