0

I want to use a function from a class.

But that class Gameplay is defined in another file.

I tried to declare it like this.

class Gameplay;
bool Gameplay::UpdateBF(MPlayer *p);

The first line went alright. but the second line had a problem like

declaration of 'bool Gameplay::UpdateBF(MPlayer*)' outside of class is not definition [-fpermissive]

I need that class and functions in both files.

What should I do?

ymoreau
  • 3,402
  • 1
  • 22
  • 60
Master
  • 1
  • 1

2 Answers2

1

Member functions must be declared in the class definition. To declare a member function in multiple source files, the class must be defined in each of the files. The definition must be exactly identical in each file.

The convention solution is to place the class definition in a separate file, and include (using the #include directive) that file from other files that depend on the class definition. Such included files are called headers. Include guards need to be used with such header, to prevent multiple definition of the class within a single translation unit.

eerorika
  • 232,697
  • 12
  • 197
  • 326
0

You need to include header file, the file contain your class from where you wan to use your function like #include "your_file_name.h" make sure your file's extension is .h to make header file user this

#ifndef _YourHeader
#define _YourHeader
  //code
#endif