getter

Better practice for heap object getters / setters in C++

百般思念 提交于 2019-12-12 01:22:24
问题 I'm currently having Type1 &GetType1() const { return *this->type1; } void SetType1(const Type1 &type1) { *this->type1 = type1; } and in the class definition class Type2 { public: Type2(); virtual ~Type2(); Type1 &GetType1() const; void SetType1(const Type1 &type1); private: Type1 *type1 = nullptr; } And in main int main() { Type2 *type2 = new Type2(); Type1 *newType1 = new Type1(); type2->SetType1(*newType1); delete type2; delete newType1; } everywhere in my project. It seems to me that this

Conventional Programming: How do you return two Types of primitive ('int and 'string') from “get” method?

强颜欢笑 提交于 2019-12-11 19:09:05
问题 Trying to print out age and name of an Object using "get" method. However, my get method return type is string: public String displayProfile() { System.out.print(getName() + getAge()); Hence the error: This method must return a result of type String Here is my main method: if user enters '2' from the "menu" where (2 == profile) the program should display user's name and age . Side note: To select "friends" from menu, user will enter '3' (3 = friends). public static void main(String[] args) {

&__get() issues, again. Major frustration is afoot

末鹿安然 提交于 2019-12-11 18:19:19
问题 Alrighty, I'm getting quite frustrated, namely because I thought I had this issue solved, or had accomplished this successfully before. Quick preliminary: PHP 5.3.6. Error reporting cranked to 11. ( -1 actually; future safe, all errors/notices ) I have a class, it aggregates request parameters. For giggles here is a stripped down version: class My_Request{ private $_data = array(); public function __construct(Array $params, Array $session){ $this->_data['params'] = $params; $this->_data[

Symfony2, validation on getters, show error on form

别说谁变了你拦得住时间么 提交于 2019-12-11 14:01:33
问题 I have a problem with errors using Symfony2 FormComponent. I've validation for getters in bundle: getters: someGetter: - MyOwnValidator: { message: "Fail"} After that, I want to validate form and show errors: {{form_errors(form)}} returns to me bunch of errors (including error for someGetter), but {{form_errors(form.someGetter)}} doesn't return anything. Any ideas? UPDATE I've found the solution. Field, for which I implemented validation (someGetter) is a collection type without 'error

C# - What should I do when every inherited class needs getter from base class, but setter only for ONE inherited class

我的梦境 提交于 2019-12-11 13:57:18
问题 I have a abstract class called WizardViewModelBase. All my WizardXXXViewModel classes inherit from the base abstract class. The base has a property with a getter. Every sub class needs and overrides that string property as its the DisplayName of the ViewModel. Only ONE ViewModel called WizardTimeTableWeekViewModel needs a setter because I have to set wether the ViewModel is a timetable for week A or week B. Using 2 ViewModels like WizardTimeTableWeekAViewModel and

Passing String values from custom dialog to another activity

穿精又带淫゛_ 提交于 2019-12-11 11:37:31
问题 A custom dialog is being used to take in user input, and then these values are being passed to another activity using getter methods. But when I pass the values to a method that outputs the string values to a CSV file, shipName , analystName etc the values appear as empty in the file like this, " " although I have entered the values in the dialog. I debugged the problem by watching the String values in the debug menu's expression window, shipName and analystName but the values never update in

How to use getters to return an image in java?

此生再无相见时 提交于 2019-12-11 09:42:06
问题 I have a class which has among its attributes an Image. I made a simple getter to return this image.. public Image getImage() { return image; } Later I try to use this getter in a drawImage() but do not get an image. g.drawImage(c.getImage(), c.getXcord(), c.getYcord(), null, this); As you can see I have other getters for this class (getXcord, getYcord) which work fine, but I can't seem to get the image. Here the class WoodlandCreatures public class WoodlandCreatures extends Animals { public

What actually happens when calling a getter function for an instance variable(that is an object)?

爱⌒轻易说出口 提交于 2019-12-11 08:58:44
问题 Lately I have had a constant battle with a function causing a SEGFAULT randomly. After doing some extra work in trying to find out the problem, I have come up with the following: All code posted via pastebin: BUILD 1:This is the original code, it causes the following SEGFAULT (given after link) http://pastebin.com/huzcqnDA SEGFAULT: #0 6FC657AC libstdc++-6!_ZNKSs4_Rep12_M_is_leakedEv() (Z:\CPP Programming\CodeBlocks\MinGW\bin\libstdc++-6.dll:??) #1 6FC89FDB libstdc++-6!_ZNSs4_Rep7_M

vuex getter with argument written in Typescript

大城市里の小女人 提交于 2019-12-11 07:39:03
问题 One can create a vuex store getter which takes a parameter argument as illustrated here: https://vuex.vuejs.org/en/getters.html I'm using Typescript (https://github.com/hmexx/vue_typescript_starter_kit) to write my code, but I can't figure out how to write a getter that takes a parameter argument. ie, the following does not seem to work: export function getItemById(state : State, id : Number) : MyItem | undefined { if(id === undefined) { return undefined; } for(const item of state.items) { if

adding an object to an array in for loop. with set and get.

爷,独闯天下 提交于 2019-12-11 07:36:22
问题 Im a little confused on adding objects to an array of 7 objects. I have a for loop and I want to add an item object with 3 arguments. I have used set and get for this. At the end of the for loop, id like to .add item object to the array list. When I try to do this I get an error: Exception in thread "main" java.lang.NullPointerException at item.add(item.java:88) at homework3main.main(homework3main.java:38) There are no errors flags on the lines 88 in item class and 38 in main, so I dont know