c++ - Run member function of an object in separate file -
i have separate files functions , variables use in program; header file , implementation file.
file.hpp:
#ifndef file_h #define file_h #include <sfml/graphics.hpp> extern sf::font sffont; #endif // file_h
file.cpp:
#include "file.hpp" sf::font sffont; sffont.loadfromfile("ubuntu.ttf"); // <- error
my problem on line i've commented on. except line run member function "loadfromfile". instead, error: "error: ´sffont´ not name type". how solve this?
as can see use library sfml, don't think it's relevant.
lines such as
sffont.loadfromfile("ubuntu.ttf");
are valid inside other functions.
if want able make function call, can use helper function initialize dummy variable , make function call in helper function.
static int init() { sffont.loadfromfile("ubuntu.ttf"); return 0; } int dummy = init();
Comments
Post a Comment