non-static

how to pass a non static-member function as a callback?

倖福魔咒の 提交于 2019-11-28 01:56:55
io_iterator_t enumerator; kern_return_t result; result = IOServiceAddMatchingNotification( mNotifyPort, kIOMatchedNotification, IOServiceMatching( "IOFireWireLocalNode" ), serviceMatchingCallback, (void *)0x1234, & enumerator ); serviceMatchingCallback((void *)0x1234, enumerator); if i declare serviceMatchinCallback as static then it works, but i do not want it to be static. Is there a way to pass it a non-static callback function? Thank you You could keep it static, but use the userdata to store the this pointer in addition to whatever other userdata you want (by packing them into a structure

Non-static method … should not be called statically

◇◆丶佛笑我妖孽 提交于 2019-11-27 20:05:06
I have recently done an update to PHP 5.4, and I get an error about static and non-static code. This is the error: PHP Strict Standards: Non-static method VTimer::get() should not be called statically in /home/jaco/public_html/include/function_smarty.php on line 371 This is the line 371: $timer = VTimer::get($options['magic']); I hope somebody can help. mamdouh alramadan That means it should be called like: $timer = (new VTimer)->get($options['magic']); The difference between static and non-static is that the first one doesn't need initialization so you can call the classname then append :: to

What is the difference between static methods in a Non static class and static methods in a static class?

戏子无情 提交于 2019-11-27 12:02:41
I have two classes Class A and ClassB: static class ClassA { static string SomeMethod() { return "I am a Static Method"; } } class ClassB { static string SomeMethod() { return "I am a Static Method"; } } I want to know what is the difference between ClassA.SomeMethod(); and ClassB.SomeMethod(); When they both can be accessed without creating an instance of the class, why do we need to create a static class instead of just using a non static class and declaring the methods as static? The only difference is that static methods in a nonstatic class cannot be extension methods . In other words,

What Cases Require Synchronized Method Access in Java?

守給你的承諾、 提交于 2019-11-27 11:16:54
问题 In what cases is it necessary to synchronize access to instance members? I understand that access to static members of a class always needs to be synchronized- because they are shared across all object instances of the class. My question is when would I be incorrect if I do not synchronize instance members? for example if my class is public class MyClass { private int instanceVar = 0; public setInstanceVar() { instanceVar++; } public getInstanceVar() { return instanceVar; } } in what cases

Accessing class member from static method

筅森魡賤 提交于 2019-11-27 07:13:02
问题 I know there are a lot of threads talking about this but so far I haven't found one that helps my situation directly. I have members of the class that I need to access from both static and non-static methods. But if the members are non-static, I can't seem to get to them from the static methods. public class SomeCoolClass { public string Summary = "I'm telling you"; public void DoSomeMethod() { string myInterval = Summary + " this is what happened!"; } public static void DoSomeOtherMethod() {

Why a non-static inner-class cannot have static members (fields and methods)? [duplicate]

倖福魔咒の 提交于 2019-11-27 03:23:19
问题 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 to the object of the outer-class. But why can't a non-static inner-class have static members? The Java designer just have to disallow the access of non-static outer-class fields inside a static method of the inner-class, it would make more sense, non?

Why do I get “non-static variable this cannot be referenced from a static context”?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 17:54:16
I have a very simple class which I want to use as a subclass of another one. But when I put its code in the parent's class I get : non-static variable this cannot be referenced from a static context On the other hand when I put the sublass GenTest 's class code outside the the "parent's" class code - JavaApp1 I do not get this error. public class JavaApp1 { class GenTest { @Deprecated void oldFunction() { System.out.println("don't use that"); } void newFunction() { System.out.println("That's ok."); } } public static void main(String[] args) { GenTest x = new GenTest(); x.oldFunction(); x

C++ Overload Static Function with Non-Static Function

不羁的心 提交于 2019-11-26 16:39:40
I would like to print two different things depending on whether a function is called statically with Foo::print() or from an instance of Foo foo; foo.print(); EDIT: Here is a class definition that definitely does not work, as answered by a few people already. class Foo { string bla; Foo() { bla = "nonstatic"; } void print() { cout << bla << endl; } static void print() { cout << "static" << endl; } }; However, is there a good way of achieving this effect? Basically, I would like to do: if(this is a static call) do one thing else do another thing Phrased in another way, I know PHP can check if

What is the difference between static methods in a Non static class and static methods in a static class?

六月ゝ 毕业季﹏ 提交于 2019-11-26 15:52:32
问题 I have two classes Class A and ClassB: static class ClassA { static string SomeMethod() { return "I am a Static Method"; } } class ClassB { static string SomeMethod() { return "I am a Static Method"; } } I want to know what is the difference between ClassA.SomeMethod(); and ClassB.SomeMethod(); When they both can be accessed without creating an instance of the class, why do we need to create a static class instead of just using a non static class and declaring the methods as static? 回答1: The

C# error: “An object reference is required for the non-static field, method, or property”

ⅰ亾dé卋堺 提交于 2019-11-26 12:24:02
I have two classes, one for defining the algorithm parameters and another to implement the algorithm: Class 1 (algorithm parameters): using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace VM_Placement { public static class AlgorithmParameters { public static int pop_size = 100; public static double crossover_rate = 0.7; public static double mutation_rate = 0.001; public static int chromo_length = 300; public static int gene_length = 4; public static int max_allowable_generations = 400; static Random rand = new Random(); public static double random_num