Questions tagged [static-functions]

124 questions
9
votes
4 answers

Best simple way to mock static/global function?

I have a simple almost value-like class like Person: class Person { public: Person(ThirdPartyClass *object); virtual ~Person(void); virtual std::string GetFullName() const; virtual int GetAge() const; virtual int…
User
  • 62,498
  • 72
  • 186
  • 247
5
votes
1 answer

SWIG support for inheritance of static member functions

SWIG doesn't wrap inherited static functions of derived classes. How it can be resolved? Here is a simple illustration of the problem. This is a simple C++ header file: // file test.hpp #include class B { public: static void stat() {…
Vahagn
  • 4,670
  • 9
  • 43
  • 72
5
votes
2 answers

Is it acceptable to mix static and non static methods in one class?

I have a relatively simple question, and although there are many posts about it on Google, I cannot find a single one that simply answers the question. So the short question is "Is it acceptable to mix static and non static methods in one class?". I…
Typhoon101
  • 2,063
  • 8
  • 32
  • 49
4
votes
3 answers

PHP Private Static Function

I am a junior PHP programmer. I still have a lot to learn. That's why I ask this question. In a class you have a public function which you can call it from outside that class. Sometimes you have a private function which you can call several times in…
O Connor
  • 4,236
  • 15
  • 50
  • 91
3
votes
4 answers

php static functions vs instance functions, basics

I'm trying to learn when static functions should be used, and have had a difficult time finding an answer my questions. I am creating a class User, which is related to a class Group. If I have a user id and I want to get a user object from that, is…
Reese
  • 1,746
  • 1
  • 17
  • 40
3
votes
2 answers

C++ Static function duplication

Let's say I have a class with a static function. The class's constructor does a pthread_create using the static function as its entry point. My question is: If I had multiple instances of this class, would they all run their own thread using that…
John Humphreys
  • 37,047
  • 37
  • 155
  • 255
3
votes
1 answer

Static function vs Static member functions C++

I've been reading a bit about static functions and static member functions. From my understanding if a function is declared static then this function is only visible to it's translation unit and nowhere else. A static member function instead is a…
user8469759
  • 2,522
  • 6
  • 26
  • 50
3
votes
1 answer

iOS how to call a static Objective-C method from C function?

I'm working with a legacy library which allows me to call a C function in response to some event. I can not pass parameters to the C function. I want the C function to raise the event to Objective-C code. I can not find a clear example, and the…
Alex Stone
  • 46,408
  • 55
  • 231
  • 407
3
votes
1 answer

How to call static library function in a C++ class?

I have class whose header file is defined as: namespace mip { class CustomStatic { public: static const char* GetVersion(); }; } And class file is defined as: #include "CustomStatic.h" namespace mip { static const…
3
votes
3 answers

Hiding 'static' class variables

So I recently found some source code which used a particular technique(idiom?) I hadn't seen before; to put it simply; instead of using a static variable for the class in question, it used a local variable inside the classes source…
hiddensunset4
  • 5,825
  • 3
  • 39
  • 61
3
votes
2 answers

C++ calling a static function from another static function

have a static function in a header file class Diagnostics { public: static void functionA(){ } static void functionB(){ some code //works fine until enters the loop below variable_name // works fine here. if…
cyrux
  • 233
  • 5
  • 15
3
votes
1 answer

PHP dynamic class names with static functions

I found some strange PHP behaviour, I'm interested if someone could explain me why some parts of this code works, while others don't. PHP can create new classes dynamically when class names are stored in variables. And it works fine since I'm using…
balping
  • 7,518
  • 3
  • 21
  • 35
3
votes
3 answers

C++ file-scope static functions

When should I consider using static functions defined at file scope? I typically use them when the task done in one such function doesn't really belong in member functions of any class and when such a task is only needed (repeatedly) in a certain…
DigitalEye
  • 1,456
  • 3
  • 17
  • 26
3
votes
1 answer

Can I invoke a static function from another compilation unit by using its address?

Possible Duplicate: Static function access in other files IIRC, a static function is not visible outside of own "compilation unit", which I think is a .C file. Can I pass its address as a parameter to a function in another unit so that the second…
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
3
votes
2 answers

How can I assign a value to public variable from inside static function in php?

I tried $this-> but could not assign a value to $first_name and $last_name variable. Without removing static feature of the function and without inserting static feature to variables, how can I echo full_name()? Here is the code :
kalaba2003
  • 1,231
  • 3
  • 20
  • 33
1
2
3
8 9