- #1
- 77
- 47
- TL;DR Summary
- In C++, how to run a method from an object that was created in a separate file.
I have created an object for the class Timers in timer_functions.cpp, and I need to run a method associated with that object ( test_method() ) from interrupts.cpp.
I've tried many things but have been unsuccessful. Any ideas would be appreciated. Here is some sample code:
classes.hpp
classes.cpp
timer_functions.cpp
interrupts.cpp
I've tried many things but have been unsuccessful. Any ideas would be appreciated. Here is some sample code:
classes.hpp
C++:
#pragma once
class Timers {
public:
void test_method(void);
private:
int testVariable;
};
classes.cpp
C++:
#include classes.hpp
void Timers::test_method(void) {
testVariable++;
}
timer_functions.cpp
C++:
#include classes.hpp
Timers myTimerObject; // create the object
C++:
#include classes.hpp
extern Timers myTimerObject; // this doesn't eliminate the build error
void timer_interrupt(void) {
myTimerObject.test_method(); // trying to run the objects method, but BUILD ERROR
}
Last edited by a moderator: