-4

For example in the following code:

class mixedFraction {
    public:
        mixedFraction();    //constructor
        void add(mixedFraction f);     //The functoin I want to define in cpp file
}

I know that to declare constructor in cpp is

<class name> :: <constructor name>(<type> <name>, ...);

But I try the samething with function it is wrong

mixedFraction::void add(mixedFraction f);

How can I do to make it correct?

Leon Ma
  • 303
  • 4
  • 13

1 Answers1

1

You need to put the return type before the class name:

void mixedFraction::add (mixedFraction f) {
     //...
}

This kind of thing should be covered in your introductory book. If you don't have one I'd recommend buying/renting/stealing one of these.

Community
  • 1
  • 1
TartanLlama
  • 63,752
  • 13
  • 157
  • 193
  • Ok, thanks. I know this is fundamental, but our teacher hasn't taught us class yet, and there is homework about class. And we don't have a textbook, so... Anyway, thanks. – Leon Ma Nov 27 '15 at 15:01