0

My class Bloque is a friend of my other class user and i want to pass an int y of my user class to a function called void colision() on my Bloque class.

So I tried this:

# user.h #

class user
{
    private:
        int y;
    friend class Bloque;
};

# bloque.h #

class user;
class Bloque
{
    public:
        void mover();
        void colision(user& f);
};

# bloque.cpp # 

#include "user.h"
#include "bloque.h"
#include <iostream>

void Bloque::mover(){ colision(user& f); }

void Bloque::colision(user& f){ cout << f.y; }

When i try to compile it, i get two errors:

In member function 'void Bloque::mover()':
bloque.cpp [Error] expected primary-expression before '&' token
bloque.cpp [Error] 'f' was not declared in this scope
Makefile.win    recipe for target 'bloque.o' failed```
precaca
  • 3
  • 2
  • 1
    Please read about [how to ask good questions](http://stackoverflow.com/help/how-to-ask), as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). And then learn how to create a [mcve] to show us. Lastly please edit your question to include the *full* and *complete* error output, including any possible informational notes. And copy-paste the build output with the errors, as text of course. – Some programmer dude Apr 03 '19 at 13:36

1 Answers1

1

Your forward declaration looks correct.

The problem is in this line:

void Bloque::mover() { 
   colision(user& f); 
}

Your variable f does not exist. I don't understand what you are trying to do exactly. If you are planning to call Bloque::colision with a variable of user type you should first declare it:

void Bloque::mover() { 
   user us;
   colision(us); 
}
mohabouje
  • 3,867
  • 2
  • 14
  • 28