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)
tr(wp), pmem(pmf)
{ }
int Dog::FunctionObject: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:perator->*(PMF pmf) //THIS IS LINE 25, see below
{
return FunctionObject(this, pmf);
}
Dog::FunctionObject::FunctionObject(Dog* wp, PMF pmf)
tr(wp), pmem(pmf)
{ }
int Dog::FunctionObject: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
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)
tr(wp), pmem(pmf)
{ }
int Dog::FunctionObject: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:perator->*(PMF pmf) //THIS IS LINE 25, see below
{
return FunctionObject(this, pmf);
}
Dog::FunctionObject::FunctionObject(Dog* wp, PMF pmf)
tr(wp), pmem(pmf)
{ }
int Dog::FunctionObject: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