class

How to create array from a class constuctor?

筅森魡賤 提交于 2019-12-25 03:47:53
问题 So basically I have a class with my program and it's constructing rain elements for my animation. I was wondering how can I use arrays to create say 50 objects from this class but at the same time alternate the data in the objects. void setup() { size (400,400); noStroke(); rain = new Rain(20,random(0,10),3,15); rain2 = new Rain(random(15,35), random(70,110),3,15); } void draw() { background(0); rain.colour(125,155,100); rain.display(); rain2.colour(125,155,100); rain2.display(); } This is

Best method to cache objects in PHP?

五迷三道 提交于 2019-12-25 03:43:19
问题 I'm currently developing a large site that handles user registrations. A social networking website for argument's sake. However, I've noticed a lag in page loads and deciphered that it is the creation of objects on pages that's slowing things down. For example, I have a Member object, that when instantiated with an ID passed as a construct parameter, it queries the database for that members' row in the members database table. Not bad, but this is created each time a page is loaded; and called

Why defining class headers without CUDA __device__ attribute works? (C++)

故事扮演 提交于 2019-12-25 03:39:56
问题 I have a .h file with the following declarations: class Foo{ public: inline int getInt(); }; and my .cu file defines the following: __device__ int Foo::getInt(){ return 42; } This is pretty awesome, because althought I cannot actually call getInt from host, I can include the .h file in .cpp files so I have the type declaration visible for the host. But for me it doesn't seem it should work, so why I dont need to put the __device__ attribute on the .h file? 回答1: If it works, it should not. It

Array withother classes - object - Java

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 03:39:34
问题 I have 3 classes: Course , CourseEntry and Transcript . In transcript, I have a function to add courses, like that: public class Transcript { CourseEntry coursestaken[] = new CourseEntry[6]; public void addCourse(Course course) { coursestaken[lastIndexOf(getCoursestaken())] = new CourseEntry(course); } (lastIndexOf gives me the empty array index - it's working on) And in my CourseEntry : public class CourseEntry { Course course; char grade = 'I'; public CourseEntry(Course course) { this

Cake PHP custom validation rule

一曲冷凌霜 提交于 2019-12-25 03:34:33
问题 I got a problem with a custom validation rule in Cake 2.X I want to check if the entered zipcode is valid and therefore a function in the class zipcode is called from the class post. But the validation returns false all the time. Appmodel in class post (rule-3 is it): 'DELIVERYAREA' => array( 'rule-1' => array( 'rule' => array('between', 5, 5), 'message' => 'Bitte eine fünfstellige Postleitzahl eingeben' ), 'rule-2' => array( 'rule' => 'Numeric', 'message' => 'Bitte nur Zahlen eingeben' ),

Template and class heritance

孤人 提交于 2019-12-25 03:26:34
问题 The code below does not produce what I want. #include <iostream> #include <vector> #include <cstdlib> using namespace std; template<typename T> class Parent; template<typename T> class Child1; template<typename T> class Child2; template<typename T> T fcn_default(const Parent<T> &obj, const T &phit){ return 3.2 + phit; } template<typename T> T fcn_mod1 (const Child1<T> &obj, const T &phit){ return 1.2 + phit; } template<typename T> T fcn_mod2 (const Child2<T> &obj, const T &phit){ return 2.2 +

Display and add methods for adjacency list graph

谁说胖子不能爱 提交于 2019-12-25 03:24:14
问题 This is my third time for creating a graph using adjacency list in c++. It's important to use OOP. I feel like the answer to this problem is really simple, but I can't manage to fix and improve my code. There is it: #include <iostream> #include <algorithm> #include <fstream> #include <vector> using namespace std; struct Edge { int begin; int end; }; class Graph { private: int numOfNodes; vector<vector<int>> baseVec; public: Graph(int numOfNodes) { //baseVec->resize(numOfNodes, vector<int>

Insert values in class without explicit writing them

一个人想着一个人 提交于 2019-12-25 03:22:12
问题 I have some huge classes and don't want to write them all out for testing, because it's a huge effort and I could forget some values what makes the test invalid. Messages = new List<Request.Notif.NotifRuleMessages> { new Request.Notif.NotifRuleMessages { Code = 1234, Message = new List<Request.Notif.NotifRuleMessagesMessage> { new Request.Notif.NotifMessagesMessage { Status = new Request.Notif.NotifMessagesMessageStatus { Code = 1, Bool = true, Test1 = "Test", Test2 = "Test" }, Rules = new

How do I pass an object by reference inside parameters?

被刻印的时光 ゝ 提交于 2019-12-25 03:11:10
问题 In order to get... void MinPriority::createArray(string targetVertex, Graph & graph) { vector <list <Graph::Edge> >& adjList = graph.get_adjList(); } to work I need to pass in Graph &graph by reference from another function: void Graph::MST_PRIM() { MinPriority priority; for(unsigned int i = 0; i != adjList.size(); i++) { priority.createArray(adjList[i].front().m_vertex, /*...*/); } } what would i put into /*...*/ to get createArray to work? Here is a rough example of what class Graph looks

Python class - Set & Delete methods?

浪尽此生 提交于 2019-12-25 03:06:25
问题 First I'd like to mention that I am completely new to Python and I've found it a bit difficult to transition from C++. I apologize if my question comes off as elementary. I have a class for 'songs' which I have initialized as following. It takes in data from a file that contains a song's ID, name, genre etc. all separated by :: . def __init__(self): self.song_names = dict() self.song_genres = dict() def load_songs(self, song_id): f = open(song_id) for line in f: line = line.rstrip() component