Questions tagged [non-static]

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).

525 questions
3
votes
3 answers

non-static template member : possible?

Is it possible to create non-static template field in a class? If no, how to workaround? Such fields should be created at compile time as needed. Example I have a lot of B-class, like B1,B2,B3. (In real case, they have more meaningful…
javaLover
  • 6,347
  • 2
  • 22
  • 67
3
votes
2 answers

An object reference is required for the nonstatic field, method, or property

I know people have asked about this question before but the scenario's were too specific and I am confused about the fundamentals. I have two basic versions of a C# program, one that works, and one that doesn't. I would love it if someone could…
Simflare
  • 39
  • 1
  • 1
  • 3
3
votes
4 answers

c++ pass data source function as parameter

I have a static function: void E::createEP(std::list* ret, double length, double (*getHeight)(double)) { // magic double sampleIntervall = //from magic double dist = 0; while (length - dist > -0.1) { ret->push_back(dist,…
Niklas
  • 33
  • 4
3
votes
4 answers

How does non-static method access static members in java?

Consider this: class SomeClass { static int a; int method() { int b = a; return b; } } How does a is being accessed in method? Is it this.a or someClass.a? EDIT: Sorry if I'm not clear in my question. What I want to know is:…
Alvin3001
  • 109
  • 1
  • 9
3
votes
7 answers

Java Beginner Question : What is wrong with the code below?

public class Function { public static void main(String args[]) { System.out.println(power(3,2)); System.out.println(power(3,2)); System.out.println(power(2)); } public long power(int m) { return m*m; } …
Serenity
  • 4,968
  • 19
  • 65
  • 104
3
votes
10 answers

Use function from other class without modifying it (static reference to the non-static method)

I have a class in Java that is used to get the Date. I want to know how to access this class WITHOUT changing it. (The code i in German, but it's just a couple words) Here is the class that I can't change: import java.util.Calendar; public class…
3
votes
4 answers

static method with polymorphism in c++

I have a weird issue using polymorphism. I have a base class that implements a static method. This method must be static for various reasons. The base class also has a pure virtual method run() that gets implemented by all the extended classes. I…
Ori
  • 4,961
  • 10
  • 40
  • 39
3
votes
4 answers

static synchronised method vs non static synchronised method

I have a class class Foo{ static synchronized get(){} synchronized() getMore(){} } I have 2 objects Foo.get() and f.getMore() running in 2 different threads t1 and t2. i had a dobuts whether when thread t1 had got a lock on the class can…
user1954799
  • 69
  • 1
  • 2
2
votes
5 answers

Static reference to non-static field Java error

I'll preface this by saying that I've been a longtime fan of Stack Overflow, and over the past few semesters I've usually been able to find the answer to all my questions without actually asking one. However, I've been having problems with a stack…
1991DBA
  • 805
  • 1
  • 9
  • 18
2
votes
1 answer

c++ why non-static member function is a prvalue?

I would like too know the rationale behind o.f and o->f being prvalues, where o is an object, and f is a non-static member function. EDIT 1 My point is that putting it into a prvalue category seems to be tantamount to an ad hoc decision as even…
2
votes
1 answer

Error: non-static data member declared ‘auto’

I am making a class called "StateMachine" to make other classes that inherit that logic. Trying to make the "State" structure store a pointer to the function to execute in that state, I have found myself needing to use lambda functions. However, I…
Yawin
  • 23
  • 4
2
votes
0 answers

When do you precede non-static GameObject methods and properties with gameObject in Unity?

For properties, layer needs gameObject to precede it but transform doesn't. For methods, SetActive() needs gameObject to precede it but GetComponent() doesn't. Second question: is there a convention to use gameObject.[method/property name] at…
2
votes
1 answer

How to change an instance variable of all instances of a class at once, Java

I want to have multiple instances of a class, but be able to change all non-static instances of a variable at once. Maybe this code will be more clear: public class Example { public int _x; //_x and _y are NOT static public int _y; …
2
votes
3 answers

Can't call method from another class in Java

I'm new to Java and honestly its OOP focus is quite taxing for me at the moment. For an Uni project where we're meant to practice this focus, I'm tasked with creating at least 2 classes: One class should be for an airline customer and the other…
Dasphillipbrau
  • 524
  • 2
  • 8
  • 17
2
votes
1 answer

how to declare a var of the type of a member var of some struct?

I want to get codes like this: struct Order_t { time_point order_time; // some other fileds }; template void onTimer( time_point tp_now ) { auto tp0 = …
Leon
  • 1,489
  • 1
  • 12
  • 31