My code is supposed to work, I have checked for missing parenthesis and semicolon. And I also copied the code directly when watching a tutorial on Youtube. Still, I was not able to get it to work.
Main class
#include <iostream>
#include "Another.h"
extern void myFunction(); // Initializing function from another class using extern keyword
int main()
{
myFunction(); // calling the function
}
Another.h
#ifndef ANOTHER_H
#define ANOTHER_H
class Another
{
public:
void myFunction(); //Function prototype
};
#endif
Another.cpp
#include "Another.h"
#include <iostream>
void Another::myFunction() // Function body
{
std::cout << "This is a function from another source file." <<std::endl;
}
The error it is giving me is "undefined reference to myFunction()". Is it my compiler?
Aucun commentaire:
Enregistrer un commentaire