non-static

What does “operator = must be a non-static member” mean?

旧街凉风 提交于 2019-11-26 09:12:47
问题 I\'m in the process of creating a double-linked list, and have overloaded the operator= to make on list equal another: template<class T> void operator=(const list<T>& lst) { clear(); copy(lst); return; } but I get this error when I try to compile: container_def.h(74) : error C2801: \'operator =\' must be a non-static member Also, if it helps, line 74 is the last line of the definition, with the \"}\". 回答1: Exactly what it says: operator overloads must be member functions. (declared inside the

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

半城伤御伤魂 提交于 2019-11-26 06:07:56
问题 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(

C++ Overload Static Function with Non-Static Function

不羁的心 提交于 2019-11-26 04:51:15
问题 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

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

感情迁移 提交于 2019-11-26 02:21:57
问题 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

Difference between Static methods and Instance methods

淺唱寂寞╮ 提交于 2019-11-25 22:48:37
问题 I was just reading over the text given to me in my textbook and I\'m not really sure I understand what it is saying. It\'s basically telling me that static methods or class methods include the \"modifier\" keyword static. But I don\'t really know what that means? Could someone please explain to me in really simple terms what Static or Class Methods are? Also, could I get a simple explanation on what Instance methods are? This is what they give me in the textbook: There are important practical

calling non-static method in static method in Java [duplicate]

ε祈祈猫儿з 提交于 2019-11-25 21:49:56
问题 This question already has an answer here: Cannot make a static reference to the non-static method 8 answers I\'m getting an error when I try to call a non-static method in a static class. Cannot make a static reference to the non-static method methodName() from the type playback I can\'t make the method static as this gives me an error too. This static method cannot hide the instance method from xInterface Is there any way to get round calling an non-static method in another static method?

Non-static variable cannot be referenced from a static context

允我心安 提交于 2019-11-25 21:32:51
问题 I\'ve written this test code: class MyProgram { int count = 0; public static void main(String[] args) { System.out.println(count); } } But it gives the following error: Main.java:6: error: non-static variable count cannot be referenced from a static context System.out.println(count); ^ How do I get my methods to recognize my class variables? 回答1: You must understand the difference between a class and an instance of that class. If you see a car on the street, you know immediately that it's a