logr not accessible from subs?

86
views
1
6 months ago by
This might be just because I am not used to cpp lately... but it seems that logr is inaccessible from functions... it works as expected in the updatefunction, but if i call a function from update and try to log while in the sub, I get an exception and it asks if i meant clog... if i try to use clog the code will compile but I get a runtime exception.
Community: Code Character

1 Answer

0
6 months ago by
This is because the logr instance is located inside the PlayerCode class, and hence is not accessible inside free standing functions.

You can however, pass a reference to logr to your own function, as shown below :

// Make your own method, passing &logr as a param
void logString(std::string str, std::ostream &logr) {
logr << str << '\n';
}

// Inside Update function
logString("Hello World", logr);​
Please login to add an answer/comment or follow this question.

Similar posts:
Search »