473,383 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Trouble moving overloaded operator from inline

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::operator( )(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::operator->*(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::operator( )(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
Jul 22 '05 #1
2 1229
exitsfunnel wrote:
Hello,

Hi.
FunctionObject Dog::operator->*(PMF pmf) //THIS IS LINE 25, see below
{
return FunctionObject(this, pmf);
}
Dog::FunctionObject Dog::operator->*(PMF pmf)
... I've done wrong here? Thanks in advance.


I know how you feel right now ...

Cheers

Jul 22 '05 #2
Gianni Mariani wrote:
exitsfunnel wrote:
Hello,


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

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

I know how you feel right now ...

Cheers


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

-exits

Jul 22 '05 #3

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

Similar topics

4
by: Roy Yao | last post by:
Why the following code let my compiler complain an overloaded function Init()? // code begin template<class T> class BicircularList { template<class T> class Iterator; template<class T> class...
3
by: glen stark | last post by:
Hi all. I'm working with an array of member function pointers (they are all get function of the class Bead). The typedef is: typedef _real (Bead::*_beadGfp)(void); I have a class System...
6
by: Vinu | last post by:
Hi, I am maintaining a C++ project which is a server which continuously receives requeste from clients. I have noticed that we overload the new operator and in it then call malloc to allocate...
4
by: vladimir | last post by:
All, I have seemingly quite known problem, namely I need to watch overloaded in quick watch(by own vector) but I can not. It says overloaded operator is not found. And that is claimed normal...
10
by: andrew browning | last post by:
i have overlaoded all of my arithmetic operators but all are functioning as multiplication. below is a sample of the addition operator: Rational operator + (const Rational& r1, const Rational&...
2
by: B. Williams | last post by:
I have an assignment for school to Overload the operators << and >and I have written the code, but I have a problem with the insertion string function. I can't get it to recognize the second of...
5
by: raylopez99 | last post by:
I need an example of a managed overloaded assignment operator for a reference class, so I can equate two classes A1 and A2, say called ARefClass, in this manner: A1=A2;. For some strange reason...
3
by: Howard Swope | last post by:
Greetings: C++ CLR .Net 2 I have a ref class that I have created that wraps an unmanaged pointer. It acts like a smart pointer for reference counted objects for a particular library I am...
9
by: itdevries | last post by:
Hi, I've ran into some trouble with an overloaded + operator, maybe someone can give me some hints what to look out for. I've got my own custom vector class, as a part of that I've overloaded...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.