# [C++] Templates + Operator Overloading



## [I.R.A]_FBi (Apr 8, 2009)

whats wrong with this?


```
template <class n>    
purse& purse <n>::operator=(const purse& p)
{
    Cent1 = p.Cent1;
    Cent5 = p.Cent5;
    Cent10 = p.Cent10;
    Cent25 = p.Cent25;
    
    return *this;
}
```


im getting



> 74 C:\Documents and Settings\Administrator\My Documents\attempt 2\purse.h expected constructor, destructor, or type conversion before '&' token


----------



## dazed554 (Apr 9, 2009)

What exactly are you attempting to do? You shouldn't need to define the = operator for that.

Post more of your code too.


----------



## FordGT90Concept (Apr 9, 2009)

```
purse& purse <n>::operator=(const purse &p)
```

I'm not positive bu the ampersand might be the wrong place (fixed above).  If that isn't it, it is probably your <n>.  I believe that is implied.


More info here:
http://www.cs.caltech.edu/courses/cs11/material/cpp/donnie/cpp-ops.html


----------



## dazed554 (Apr 9, 2009)

FordGT90Concept said:


> ```
> purse& purse <n>::operator=(const purse &p)
> ```
> 
> ...



the & is not a problem, white space and such really doesn't have much effect in C++


----------



## Oliver_FF (Apr 10, 2009)

This is how an overloaded operator should look:


```
MyNumber MyNumber::operator+ (MyNumber param) {
  MyNumber temp;
  temp.num =  num + param.num;
  return (temp);
}
```
For a class "MyNumber".

In your code:

```
template <class n>    
purse& purse <n>::operator=(const purse& p)
{
```
whats the "*purse& purse* <n...." about?


----------

