Questions tagged [static-functions]
124 questions
1
vote
1 answer
If statement failing to evaluate condition
I have a basic class that containers two enumerators, one for input and one for output. It has two member functions which are both static. The first function is just a static function that returns a value based on the input. It will call the second…

Francis Cugler
- 7,788
- 2
- 28
- 59
1
vote
1 answer
Dealing with static functions when building a program as a library
To implement unit testing for one of my programs, I've added a makefile rule to build the program as a static library when "make check" is run. I wrap main() with #ifndef TEST_LIB and #endif (TEST_LIB is defined when it's built as a library).
Then I…

Andy Alt
- 297
- 2
- 12
1
vote
2 answers
How can you access the function from another translation unit without including any files?
I was reading about static functions and it was said that if the function is static then you can use it only in the same file. After testing it, I realized it is not true because if you include the file with a static function you can still use that…

Vegeta
- 334
- 2
- 4
- 12
1
vote
1 answer
Using a static function in c++ my prof wants me to tell main which object has the highest priority without passing anything
I was given the the following main function and I have to code the object to pass.
Here's main:
#include
#include
#include
#include
#include "ToDo.h"
using namespace std;
int getRand(int min, int range) {
…

NBell
- 11
- 1
1
vote
3 answers
Unable to call static function inside its own class
How can I call static function inside the class itself? I try self keyword instead of this but I still get error.
class Test {
static staticFunction() {
console.log('Inside static function.');
}
regularFunction() {
…

quarky
- 710
- 2
- 13
- 36
1
vote
2 answers
Set reference of function to non-static function from other c++ file
I'm trying to set a reference of a non-static function in c++. The function I'm referencing is not from the same c++ file, and I get and error saying :
Cannot create a non-constant pointer to member function.
Main.cpp
#include
#include…

LearningThings2
- 27
- 1
- 5
1
vote
4 answers
How to return function values when using method chaining in PHP?
Say I have the following class:
class Test
{
private static $instance = false;
public static function test()
{
if(!self::$instance)
{
self::$instance = new self();
}
return self::$instance;
…

Erdss4
- 1,025
- 3
- 11
- 31
1
vote
1 answer
c++ calling static function from virtual function
I have virtual method that calls static method of appropriate class:
class A{
public:
static void bar() {std::cout<<"bar A\n";}
virtual void foo(){
//Some A work...
bar();
}
};
class B : public A{
public:
static void…

Dmitry J
- 867
- 7
- 20
1
vote
1 answer
C99 static inline function with static local variable
If I write something like this in a C99 header:
static inline void f()
{
static int x = 0;
// Do something with x
}
Is it guaranteed that each module including this header gets a separate instantiation of f() and its own instantiation of x?

Silicomancer
- 8,604
- 10
- 63
- 130
1
vote
1 answer
Static function from static function
I have a class with non static functions. Because of the architecture of my program I think it will be better to use static functions since the class is just an utility. In some cases I just need one function of the class so I see unnecessary to…

Luis
- 127
- 1
- 11
1
vote
1 answer
Bind c++ static functions from another class to Lua
Hy!
My problem is simple: I have a function in the extendedgamefunctions class:
In the header:
#include "Gameitems.h"
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
};
extern std::vector>…

Bady
- 56
- 8
1
vote
1 answer
Why do static functions sometimes have non standard stack frames?
In the wikibook x86 Disassembly, it is written that sometimes there are subroutines that do not set up standard stack frames. One such case is when we declare a static function in C. The following lines have been written in the book.
When an…

crisron
- 363
- 2
- 5
- 21
1
vote
4 answers
Organizing C program with lots of static functions
I am working on a personal project and I only want to expose 3 ou 4 function.
One of the problems of this is that my .c file is getting more and more static functions. Currently it already has 21 static functions.
What would be the best way to…

AntonioCS
- 8,335
- 18
- 63
- 92
1
vote
0 answers
No Such Method Exception in Guava Set
I am getting the following exception while static method of Sets of guava collection is being used, though the method is statically imported. What could be the reason? Guava version used here is 12.0.1.
Exception in thread "Task-Thread-for…

ptntialunrlsd
- 794
- 8
- 23
1
vote
3 answers
What is the exact reason for the keyword static working differently for variables and functions
If we use static in-front of a variable, it's value remain intact for the entire cycle of the program's execution in between function calls. But if we use static with functions they become local to the file in which they are declared. I know this is…

jeevan
- 247
- 5
- 12