Trouble moving overloaded operator from inline

E

exitsfunnel

Hello,

I have the following file which compiles and runs like a charm:

//BEGIN WORKING FILE
#include <iostream>
using namespace std;
class Dog
{
public:
int run(int i) const { cout << "run\n"; return i; }
int eat(int i) const { cout << "eat\n"; return i; }
int sleep(int i) const { cout << "ZZZ\n"; return i; }
typedef int (Dog::*PMF) (int) const;
class FunctionObject
{
public:
FunctionObject(Dog* wp, PMF pmf);
int operator( )(int i) const;

private:
Dog* ptr;
PMF pmem;
};
FunctionObject operator->*(PMF pmf)
{
return FunctionObject(this, pmf);
}
};
Dog::FunctionObject::FunctionObject(Dog* wp, PMF pmf)
:ptr(wp), pmem(pmf)
{ }
int Dog::FunctionObject::eek:perator( )(int i) const
{
return (ptr->*pmem)(i);
}
int main( )
{ }
//END WORKING FILE

However, I'd like to move the 'operator->*' definition out of the
class definition as follows:

//BEGIN BROKEN FILE
#include <iostream>
using namespace std;
class Dog
{
public:
int run(int i) const { cout << "run\n"; return i; }
int eat(int i) const { cout << "eat\n"; return i; }
int sleep(int i) const { cout << "ZZZ\n"; return i; }
typedef int (Dog::*PMF) (int) const;
class FunctionObject
{
public:
FunctionObject(Dog* wp, PMF pmf);
int operator( )(int i) const;
private:
Dog* ptr;
PMF pmem;
};
FunctionObject operator->*(PMF pmf);
};
FunctionObject Dog::eek:perator->*(PMF pmf) //THIS IS LINE 25, see below
{
return FunctionObject(this, pmf);
}
Dog::FunctionObject::FunctionObject(Dog* wp, PMF pmf)
:ptr(wp), pmem(pmf)
{ }
int Dog::FunctionObject::eek:perator( )(int i) const
{
return (ptr->*pmem)(i);
}
int main( )
{ }
//END BROKEN FILE

Now I get the following compiler error:
foo.cpp:25: syntax error before '::'

The line number (25) is a bit off because of the cut and paste but, in
any case, it points to the indicated line. Can anyone tell me what
I've done wrong here? Thanks in advance.

-exits
 
G

Gianni Mariani

exitsfunnel said:
Hello,

Hi.

FunctionObject Dog::eek:perator->*(PMF pmf) //THIS IS LINE 25, see below
{
return FunctionObject(this, pmf);
}

Dog::FunctionObject Dog::eek:perator->*(PMF pmf)
... I've done wrong here? Thanks in advance.

I know how you feel right now ...

Cheers
 
E

exits funnel

Gianni said:
Dog::FunctionObject Dog::eek:perator->*(PMF pmf)



I know how you feel right now ...

Cheers

Oh man, I can't believe I missed that. Thanks for the quick reply!

-exits
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,148
Messages
2,570,838
Members
47,385
Latest member
Joneswilliam01

Latest Threads

Top