class

Managing multiple instances of same class (Java)

[亡魂溺海] 提交于 2019-12-26 05:05:05
问题 Hey I'm having some trouble managing multiple instances of the same class in a java program. I've creating a few instances of a java class that contains a few methods that add/subtract from an integer in the class, but what's happening is that the adding and subtracting is being done on all of the instances (see code below), any tips on managing these instances is most appreciated. Integerclass num1 = new Integerclass(); Integerclass num2 = new Integerclass(); Integerclass num3 = new

Managing multiple instances of same class (Java)

主宰稳场 提交于 2019-12-26 05:04:24
问题 Hey I'm having some trouble managing multiple instances of the same class in a java program. I've creating a few instances of a java class that contains a few methods that add/subtract from an integer in the class, but what's happening is that the adding and subtracting is being done on all of the instances (see code below), any tips on managing these instances is most appreciated. Integerclass num1 = new Integerclass(); Integerclass num2 = new Integerclass(); Integerclass num3 = new

Python 3: Calling a class function inside of __init__

江枫思渺然 提交于 2019-12-26 03:46:06
问题 I have a little question about python 3. I want to create a class, which is using a function from within of that class. Just like: class Plus: def __init__(self, x, y): self.x = x self.y = y self.test() def test(self): return self.x + self.y now I am doing something like a = Plus(5,6) print(a) and python is giving me <__main__.Plus object at 0x000000000295F748> and not 11 as I want it. I know that I can get 11 by a = Plus(5, 6).test() print(a) but that's not what I want. I want to call the

C++: friend as main in class

こ雲淡風輕ζ 提交于 2019-12-25 19:36:25
问题 Can main function become friend function in C++ ? #include "stdafx.h" #include <iostream> using namespace std; class A { public: A():i(10){} private: int i; friend int main(); }; int main() { A obj; cout<<obj.i; return 0; } 回答1: Can main function become friend function in C++ ? Yes, it can. The friend declaration in your class A grants function main() the right of accessing the name of its non-public data members (in this case, i ): friend int main(); The object obj is default-constructed,

Possible to use a function inside of a different classes __construct?

喜欢而已 提交于 2019-12-25 19:35:53
问题 EDIT::: So I have classes that I would like to work together. My first two establish a connection to the database: dbconn.php <?php class dbconn { protected $dbname; protected $dbuser; protected $dbpassword; protected $dbhost; protected $connection; public function __construct($dbhost, $dbname, $dbuser, $dbpass) { $this->dbname = $dbname; $this->dbhost = $dbhost; $this->dbuser = $dbuser; $this->dbpass = $dbpass; $this->connect(); } public function getConnection() { return $this->connection; }

C++: friend as main in class

杀马特。学长 韩版系。学妹 提交于 2019-12-25 19:35:39
问题 Can main function become friend function in C++ ? #include "stdafx.h" #include <iostream> using namespace std; class A { public: A():i(10){} private: int i; friend int main(); }; int main() { A obj; cout<<obj.i; return 0; } 回答1: Can main function become friend function in C++ ? Yes, it can. The friend declaration in your class A grants function main() the right of accessing the name of its non-public data members (in this case, i ): friend int main(); The object obj is default-constructed,

Putting the WordPress Loop into a class

浪子不回头ぞ 提交于 2019-12-25 18:55:33
问题 I am trying to build a framework essentially for WordPress Developers to help develop Themes and Theme Frameworks more efficiently and faster. How ever, I am having a small issue by putting the wordpress loop into a class, this is what I have: class AisisCore_Template_Helpers_Loop{ protected $_options; public function __construct($options = null){ if(isset($options)){ $this->_options = $options; } } public function init(){} public function loop(){ if(have_posts()){ while(have_posts()){ the

Having trouble implementing a nested class comparator

余生颓废 提交于 2019-12-25 18:54:46
问题 I'm implementing a Point class and trying to use a nested class to implement a comparator, which will compare based on the slope of two points. I'm having trouble implementing such comparator and don't understand how to use it in my main() function. This is the error message I got when I try to compile it: Point.java:20: error: non-static variable this cannot be referenced from a static context if (Point.this.slopeTo(pt1) > Point.this.slopeTo(pt2)) { ^ Point.java:20: error: non-static

Basics to creating a class in java [closed]

試著忘記壹切 提交于 2019-12-25 18:46:27
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . This is a simple question, but my AP Comp Sci book just doesn't explain it well enough and you guys are always useful. What is the basic way of creating a custom class in Java and creating methods within that class, then later calling those methods. I know its simple but I can't

Clases and Objects in c#

≡放荡痞女 提交于 2019-12-25 18:42:20
问题 I have the next situation Generic class: public class A { ... } and two clases: public class B: A { ... } public class C: A { ... } In some part of the code I want to do something like (list is filled previously): foreach (A item in list) { listB.add((B) item); } Is it possible to do it? I just want to bind the list of generic ítems to the list of clases extends the generic class. Thanks 回答1: You cannot do what you are trying to do because you won't be able to add items of type C to your list