128 questions
-1
votes
1
answer
21
views
Unresolved external symbol: static function declared in class defined in cpp file
my code looks like this:
//Renderer.h file
#pragma once
class Renderer {
public:
static int Test();
};
//Renderer.cpp file
#include "../Header/Renderer.h"
#include <iostream>
int ...
0
votes
2
answers
164
views
How to call a C++ member method from a C callback function with PipeWire
I am trying to adapt this PipeWire example for use with C++, as I need to carry out various processing in a C++ method. But I am not sure how I can call a C++ member method from the static callback ...
0
votes
0
answers
50
views
access to a static function using Dot operator in C++ [duplicate]
I came across with a C++ code that is vague for me due to the way of access to static function member of a class. Basically, static function members must be accessed using scope resolution operator(::)...
0
votes
1
answer
124
views
What is the difference between including a file directly and linking against it?
I found these lines in a header file (https://github.com/eyalroz/printf/blob/master/src/printf/printf.h) that is part of a printf implementation.
// If you want to include this implementation file ...
0
votes
1
answer
112
views
What's the difference between static non-member functions and non-static non-member functions? [duplicate]
What's the difference between these two non-member functions ?
static void
function1() {
std::cout << "Test" << std::endl;
}
void
function2() {
std::cout << "...
2
votes
2
answers
3k
views
JUnit Mockito: Testing a Static Method and Calling Another Stubbed Static Method Inside Not Working
class A {
public static int f1() {
return 1;
}
public static int f2() {
return A.f1();
}
}
class ATest {
@Test
void testF2() {
try (MockedStatic<A> ...
0
votes
2
answers
70
views
Why are these static functions working outside their file?
I defined the next two static functions in a file named Grafico.h.
static inline interface_t * obtener_intf_por_nombre(nodo_t *nodo, char *nombre_if) {
for (int i = 0; i < MAX_INTF_POR_NODO; ++...
0
votes
1
answer
673
views
Importing static Functions In Modularized C++ Projects
There are many functions in CRT library marked as static. How it will be imported in modularized project? Here is the code reproducing the problem.
Header.h
static auto foo() -> void {}
...
0
votes
1
answer
816
views
Angular 7 How To Access Domsanitizer Object inside a static function
I am trying to resolve the checkmarx issue which says application embeds untrusted data in the generated output.This untrusted data is embedded straight into the output without proper sanitization or ...
0
votes
1
answer
1k
views
Error: "Invalid use of member 'filename' in static member function"
I'm very new to c++ and I'm creating a Task List for a project, and I keep getting this error on both static functions within "TaskIO.cpp" when I try to run the code. The goal of the ...
1
vote
1
answer
498
views
php static function class save previous function call data
class User
{
private static $User;
public static function get()
{
if (empty(self::$User)) {
echo "Create New Object<br/>";
return self::$...
0
votes
1
answer
298
views
how can i deal with the static parameters and static functions in kotlin?
public class C {
public static string a;
public static string b;
public C(String a, String b){
this.a=a;
this.b=b;
}
public void addString(){
String result=a+b;
}
public static JSONObjet ...
1
vote
1
answer
5k
views
C++: Static member function returning an object of self static for a class with private constructor
I've a C++ snippet as below. The "getInstance()" function is trying to return a static object of the same class "CAbc". This class has a private constructor so that objects of this ...
0
votes
2
answers
1k
views
static function declarations in header files
I have a static function in a source file that is used by other functions in that same source file. Is it fine to put the declaration for that static function in the header file, even though that ...
7
votes
1
answer
10k
views
Static function vs Static member functions C++ [duplicate]
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 ...
1
vote
2
answers
2k
views
Calling Invoke within a public static function Unity
I'm getting an error that I don't understand. The simplified version of my code:
using UnityEngine;
public class RunLater : MonoBehaviour
{
public static void Do()
{
Invoke("...
1
vote
3
answers
207
views
Static member function and access operator
I was just looking through lvalue(Value categories) from cppreference.com and came across member access operator that specifies as :
In Built in Access operator of type E1.E2 :
3) if E2 is a ...
0
votes
1
answer
97
views
PHP: get derived class context in static function? i.e. differ between BaseClass::staticBaseFunc() vs DerivedClass::staticBaseFunc()
I have a base class with a static function. But I would like to have a way to know the actual class (could be the base class or a derived class) within whose context I am calling the static function.
...
2
votes
2
answers
320
views
How to declare an extension static function in Kotlin on Java Classes?
I want declaring an extension func in kotlin but on Java classes Library, I know that do in Kotlin when you resolve companion in extension function.
Like:
class Food {
companion object {
...
-2
votes
1
answer
188
views
C++ must define as static constexpr double - cant initialize static non-integral variable inside Class
// Ive found useful information in other questions relating to static variables and their initialization. I found a work around (didnt feel like solving this with a separate file as suggested here: ...
0
votes
1
answer
140
views
Call to static overloaded (class) function/method is ambiguous
In my C++ class, I have two static methods, called getInstance.
The method declarations are as follows:
public: // +++ STATIC +++
static CanCommunicator* getInstance(shared_ptr<ThreadState>...
0
votes
1
answer
91
views
Is it better to declare a function static to make it private or declaring it only on the .c file and excluding it from the header?
I'm writing a library in c and there are some functions I would like to be callable from other c file and some I would like to keep private.
I know that it is possible to hide functions outside of ...
13
votes
2
answers
3k
views
Are constexpr functions implicitly static?
If I define a function in my program.cpp:
constexpr bool isThree(const int number)
{
return number == 3;
}
is that any different from declaring it static?
static constexpr bool isThree(const int ...
3
votes
1
answer
1k
views
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 ...
0
votes
2
answers
134
views
Access to a defined property from static function
I would like to define a property in a static class, then access to this property from another static class. For this aim I have defined such a property:
public static class First
{
public ...
0
votes
1
answer
127
views
static data member(class pointer) in default argument via c++ class
my code of AvlTree class head file is as follows:
template <typename T>
class AvlTree
{
public:
template <typename T1>
friend class AvlNode;
AvlNode<T> *root;
...
3
votes
1
answer
3k
views
How to call static library function in a C++ class? [duplicate]
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 "...
0
votes
2
answers
271
views
Static member functions in namesapce [closed]
I have static member function inside my class which I would like to add in my namespace.
class A{
public:
static void func();
};
namespace myNamespace{
void A::func(){
...
}
}
int ...
1
vote
1
answer
183
views
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 ...
1
vote
1
answer
179
views
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 ...
1
vote
2
answers
1k
views
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 ...
0
votes
3
answers
2k
views
why i can't call a static member variable in an static member function like this?
everyone! there is a code snippet like the below:
testcase.cpp
#include <string>
#include <iostream>
using namespace std;
class Test {
public:
static int b ;
static void test()
...
0
votes
3
answers
208
views
Are arguments loaded into the cache for empty functions?
I know that C++ compilers optimize empty (static) functions.
Based on that knowledge I wrote a piece of code that should get optimized away whenever I some identifier is defined (using the -D option ...
0
votes
2
answers
3k
views
How to call swift static method with escaping closure in objective-c file
I have this static function written in swift that I need to call in objective-c file
static func downloadVideo(url: String, onResult: @escaping(String?) -> ()){
//some code
onResult("done")...
-1
votes
1
answer
723
views
Trying to create object using constructor inside static function in C++
I was trying to create an object inside static function using a constructor.
Here is the code
class A {
public:
A() { this->a = 50; std::cout << "constructor called... " << this &...
1
vote
1
answer
2k
views
why this error has come ? "static declaration of function follows non-static declaration"? [duplicate]
I am learning about static function and as per rule if i declare function as
a static function then i can't access this function into other c file and if i try to access then there should be an error ...
21
votes
2
answers
13k
views
gcc warns about unused static functions, but not static inline: is there a practical distinction?
My version (5.4) of gcc warns about unused static functions, even in a header file when -Wall is used. It doesn't complain if the same functions are defined static inline or simply inline.
For ...
1
vote
1
answer
78
views
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 <iostream>
#include <string>
#include <ctime>
#include <stdexcept>
#...
0
votes
0
answers
97
views
Is it worth declaring functions as static?
In C or C++ you can declare a function to be static if it is only used in a single Translation Unit (i.e. file), for example:
static int square(int a) {
return a * a;
}
This should allow the ...
1
vote
3
answers
191
views
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 ...
0
votes
2
answers
301
views
this in unevaluated context in static member functions
Why this is not allowed in unevaluated context in static member functions?
struct A
{
void f() {}
static void callback(void * self) // passed to C function
{
static_cast< ...
0
votes
0
answers
67
views
Include static functions to symbols table using CMake in Android Studio
I need to get all C/C++ functions names from disassembled library of android NDK project. Now I see only not static functions. Is there a possibility to include static functions to symbols table?
I ...
1
vote
2
answers
3k
views
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 ...
0
votes
2
answers
619
views
Order of 'static' function keyword vs return type specifier in C [duplicate]
Hopefully this is not a duplicate of a number of other questions relating to the meaning of 'static' functions in C.
We support some legacy native C code containing things along the following lines .....
0
votes
0
answers
67
views
Are Static functions in ES6 a substitute for Mixins that were used in React?
I'm new to React. Can somebody explain why ES6 is launched without any mixin support. Since, there is no support for mixins when you use React with ES6 classes.
Can we use Static functions instead of ...
0
votes
2
answers
73
views
In the C language, how to use static function of non-current file? [duplicate]
fileA.c has a static function (static int funcA())
The fileA.c can not be modified.
fileB.c How can I use the funcA()?
-2
votes
1
answer
557
views
C++ class static member function calling error
I write a project with visual studio. In the project I build a class called CSimApplianceDlg which has two members:
static UINT RecvDataFrame(LPVOID pParam) and CSerialPort m_Port
class ...
0
votes
0
answers
74
views
C++ Using static class function from another header, "class_name" has not been declared [duplicate]
EDIT:thanks for pointing me in the right direction of circular dependency. I tried removing #include "datastructure.h" from Mathfg.h, and I added a "Class ArithmeticTree" in "Matfg.h" to forward ...
0
votes
1
answer
1k
views
Use UI elements from static function
I am building a qt application in which i am have to access ui elements. but i am getting error as
invalid use of member 'foo::ui' in static member function
The code is big so cant add here.
...
1
vote
4
answers
1k
views
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 ...