472,991 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,991 software developers and data experts.

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 2751
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
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
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
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
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
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
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
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
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
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
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.