Calling a method from one class in another class

RAY

I have this class:

boer.h

#pragma once
#include <functional>
#include <iostream>

class boer
{
private:

    std::function<void(int id_)> someFun;

public:
    boer();
    ~boer();

    void setSomeFun(std::function<void(int id_)> someFun_);

    void getSomeFun();
};

boer.cpp

#include "boer.h"

boer::boer() { }

boer::~boer() { }

void boer::setSomeFun(std::function<void(int id_)> someFun_)
{
    someFun = someFun_;
}

void boer::getSomeFun()
{
    someFun(12345);
}

And this class:

aircraft.h

#pragma once
#include <functional>
#include <iostream>
#include "boer.h"

class aircraft
{
private:

    boer Boer;

public:
    aircraft();
    ~aircraft();

    void source_forSomeFun(int id_);
};

aircraft.cpp

#include "aircraft.h"

aircraft::aircraft() { }

aircraft::~aircraft() { }

void aircraft::source_forSomeFun(int lol_)
{
    std::cout << "AMAZING!!!" << std::endl;
}

And I need to connect void source_forSomeFun(int id_); in aicraft with std::function<void(int id_)> someFun; in boer. How can I do this? Maybe there is another way, but i think this method is the most preferable.

int main()
{
    aircraft Aircraft;
    boer Boer;

    Boer.setSomeFun(???); // here

    Boer.getSomeFun();

    int i;
    std::cin >> i;
    return 0;
}
user2672107
Boer.setSomeFun([&](int v){aircraft.source_forSomeFun(v);});

Use a lambda.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Django - Calling one class method from another in Class Based View

From Dev

Python Inherit from one class but override method calling another class?

From Dev

Calling a list from one method to another in the same class in Python

From Java

Calling one method from another within same class in Python

From Dev

Undefined Method - Calling a class in one file from another

From Dev

Kivy - Calling a pulsing method from one class to another

From Dev

Calling a class from another class with main method

From Dev

Calling function from one class in another class

From Java

Calling method of Another class from run() method

From Javascript

Calling a method from another method in the same class

From Java

Using a method from one class into another class

From Dev

Using a method from one class in another class

From Dev

Method returning from one class to another class

From Dev

coffeescript class - calling calling one class method from an other

From Dev

Calling a method from inside of another class

From Dev

Calling a method of the MainActivity from another class?

From Dev

Calling method from another class unsuccessful

From Java

java calling a method from another class

From Java

Calling service method from another service class

From Java

NullPointerException when calling method from another class

From Dev

JGroups RpcDispatcher calling method from another class

From Dev

calling render method from another class

From Dev

calling method in mainactivity from another class in android

From Dev

Python: Calling a decorator method from another class

From Dev

Having trouble calling a method from another class

From Dev

Syntax Error in Calling a method from another class

From Dev

calling a boolean method from another class

From Dev

Calling a method from another class in broadcast receiver

From Dev

Calling a method from another class that removes views

Related Related

  1. 1

    Django - Calling one class method from another in Class Based View

  2. 2

    Python Inherit from one class but override method calling another class?

  3. 3

    Calling a list from one method to another in the same class in Python

  4. 4

    Calling one method from another within same class in Python

  5. 5

    Undefined Method - Calling a class in one file from another

  6. 6

    Kivy - Calling a pulsing method from one class to another

  7. 7

    Calling a class from another class with main method

  8. 8

    Calling function from one class in another class

  9. 9

    Calling method of Another class from run() method

  10. 10

    Calling a method from another method in the same class

  11. 11

    Using a method from one class into another class

  12. 12

    Using a method from one class in another class

  13. 13

    Method returning from one class to another class

  14. 14

    coffeescript class - calling calling one class method from an other

  15. 15

    Calling a method from inside of another class

  16. 16

    Calling a method of the MainActivity from another class?

  17. 17

    Calling method from another class unsuccessful

  18. 18

    java calling a method from another class

  19. 19

    Calling service method from another service class

  20. 20

    NullPointerException when calling method from another class

  21. 21

    JGroups RpcDispatcher calling method from another class

  22. 22

    calling render method from another class

  23. 23

    calling method in mainactivity from another class in android

  24. 24

    Python: Calling a decorator method from another class

  25. 25

    Having trouble calling a method from another class

  26. 26

    Syntax Error in Calling a method from another class

  27. 27

    calling a boolean method from another class

  28. 28

    Calling a method from another class in broadcast receiver

  29. 29

    Calling a method from another class that removes views

HotTag

Archive