non-static is a term to define a function or field that is bound to some object instance. Without an instance, non static fields cannot be accessed and non static methods cannot be invoked. Unlike static, non-static methods can be overridden (virtual).
Questions tagged [non-static]
525 questions
14
votes
1 answer
THREAD ERROR: invalid use of non-static member function
I'm trying to understand threads in C++ but I don't know how to solve this problem.
I want to call two threads to run the function called "createS" but I get this error:
error: invalid use of non-static member function
I've read other questions…

Jacob
- 595
- 1
- 7
- 25
14
votes
3 answers
Why a non-static inner-class cannot have static members (fields and methods)?
Possible Duplicate:
Why cant we have static method in an inner class?
I know that the creation of a non-static inner-class object requires an outer-class object and the created non-static inner-class object automatically have a hidden reference…

Kewei Shang
- 949
- 3
- 11
- 27
13
votes
4 answers
How to wrap a static class in a non-static instance object (dynamically)
I have an interesting problem. I need to wrap static classes dynamically. I.e. return a non-static instance to my callers. e.g.:
public object CreateInstance(string className) {
Type t = assembly.GetType(className);
if (IsStatic(t)) {
…

gatapia
- 3,574
- 4
- 40
- 48
13
votes
3 answers
accessing static member from non-static function in typescript
I am trying to access a static member from a non-static function in the class, and I get an error saying
Static member cannot be accessed off an instance variable
this is how my code looks -
class myClass {
public static testStatic: number = 0;
…

Ravi
- 143
- 1
- 1
- 8
9
votes
7 answers
Can I place "non-static blocks" of code in class definitions?
Is there non-static block in C++?
If no, how to emulate it elegantly?
I want to replace something like :-
class C{
public: void ini(){/* some code */}
};
class D{
std::vector regis; //will ini(); later
public: C field1;
public:…

javaLover
- 6,347
- 2
- 22
- 67
9
votes
2 answers
PHP Calling self on a non-static method
Why is the 'self'-call to a non-satic method in this example working?
class A{
protected function aNonStaticMethod(){
return __class__;
}
public function aEcho(){
echo self::aNonStaticMethod();
}
}
Thanks for…

user2853437
- 750
- 8
- 27
9
votes
3 answers
What is the alternative to a non-static initialization block?
My projects had some developer who loved a non-static initialization block.
What is the alternative to this and what is the downside of this alternative? I would guess: initialize the values in the constructor ?
Why should we use a…

Dimitri Dewaele
- 10,311
- 21
- 80
- 127
8
votes
3 answers
What is a nonstatic member function?
I am being told that I can't use the 'this' keyword in a class function. I'm coming from c# and i'm used to this working, but the compiler tells me that it can only be used within nonstatic member functions.
D3DXVECTOR3 position;
void…

Dollarslice
- 9,917
- 22
- 59
- 87
8
votes
2 answers
C++ A nonstatic member reference must be relative to a specific object
Vector2D tankPos = Tank_b017191c::GetTankPosition();
I am trying to call a function from a different class but I am getting this error:
47 IntelliSense: a nonstatic member reference must be relative to a
specific
object …

BR3TON
- 91
- 1
- 1
- 4
8
votes
2 answers
non-static variable this cannot be referenced from a static context
The error comes from this line
BoardState addme = new BoardState();
For some reason the non-static variable that it is pointing at is "new". I am unclear of how I can fix this error as new is not meant to be a variable, and is not.
Looking…

John Smith
- 83
- 1
- 1
- 3
7
votes
3 answers
How to mock non static methods using PowerMock
I am trying to mock an inner method call of my test method
My class looks like this
public class App {
public Student getStudent() {
MyDAO dao = new MyDAO();
return dao.getStudentDetails();//getStudentDetails is a public
…

Bala
- 91
- 1
- 2
- 4
7
votes
4 answers
c++ pointer to non-static member functions
I have read many posts and answers about pointers to non-static member functions, but none looks able to solve my problem.
So I have created a short example to replicate my issue here: even if this example could be "solved" in different ways, for…

Mattia
- 135
- 3
- 13
7
votes
8 answers
how to pass a non static-member function as a callback?
io_iterator_t enumerator;
kern_return_t result;
result = IOServiceAddMatchingNotification(
mNotifyPort,
kIOMatchedNotification,
IOServiceMatching( "IOFireWireLocalNode" ),
…

infinitloop
- 2,863
- 7
- 38
- 55
7
votes
7 answers
How do I call a non static method from a main method?
For example, I am trying to do something like this
public class Test {
public static void main(String args[]) {
int[] arr = new int[5];
arrPrint(arr);
}
public void arrPrint(int[] arr) {
for (int i = 0; i <…
user1174868
7
votes
5 answers
Is there a way to call a non-static method from a static method?
Here's what I have.
public static void Person_home_phone_TextChanged(object sender, EventArgs e) { ... }
Is there any way to access non-static methods from the same or another class from inside this static method?
I need grab the text in the…

Glimpse
- 462
- 2
- 8
- 25