instance-variables

accessing instance variable from another template class

[亡魂溺海] 提交于 2019-12-11 14:49:45
问题 (mostly pasted from accessing variable from another class template to separate two problems) i am trying to make a system of container classes that can be used with a data loader class to load data from text files here are the two classes of data: class Customer { //... }; class Tour { std::vector<Customer*> custPtrs; //... }; these are my two container classes: template <class T> class P_VContainer { boost::ptr_vector<T> data; //... }; template <class T> class ListContainer { std::list<T>

How do I make sure each post in the Post feed shown in the home page has all its comments displayed under it?

半城伤御伤魂 提交于 2019-12-11 14:33:53
问题 I have a Post model, and a Comment model that belongs to Post. I was able to display the Post in the home view corresponding to the home controller and home action and the User/show view. Thus, in the home and user views, the posts are listed in order of creation time. I was also able to have a post form in both the user and home views and a comment form in the home and user views. The problem arises when I try to display the comment underneath each displayed Post in the home and user views.

is it bad form to use instance vars directly in ruby?

最后都变了- 提交于 2019-12-11 13:19:33
问题 Should you always create accesssors (for reading and/or writing) in ruby? If you have a class that's not meant to be reused outside, can't I just use instance variables directly? One of the problems I ran into is that it's problematic to stub out @instance_vars in tests. 回答1: Instance variables don't matter when it comes to testing. You should be testing your methods , in order to verify that they produce the correct results. When you define a reader method for an attribute, you expose that

"Instance variable 'xxx' accessed in class method…why?

耗尽温柔 提交于 2019-12-11 10:49:05
问题 So please forgive me as I am very new to stackoverflow and to ios programming in general. I am attempting to change the text of a button i have, replacing current text with a date string ( dateStringForInput ) I am passing in from another class. The button is called myTodayButton and is declared in my .h file for my class inputMilesViewController ... @property (strong, nonatomic) IBOutlet UIButton *myTodayButton ; Below is the code from my .m. +(void) changeButtonText:(NSString*)

Hidden instance variables in before_filter method

≡放荡痞女 提交于 2019-12-11 10:12:02
问题 Is it a good practice to hide instance variable initialization in private methods? For example, I have a user controller with some actions: class UsersController < ApplicationController before_filter :get_user, only: [:show, :edit, :update, :destroy] before_filter :set_user, only: [:new, :create] def index @users = User.all end def show end def new end def edit end def create if @user.save redirect_to @user, notice: 'User was successfully created.' else render action: 'new' end end def update

Python Eclipse type casting intellisense work-around

守給你的承諾、 提交于 2019-12-11 09:46:25
问题 Say I have the following two classes. class TopClass: def __init__(self): self.items = [] class ItemClass: def __init__(self): self.name = None And I want to use that in the following way: def do_something(): myTop = TopClass() # create two items item1 = ItemClass() item1.name = "Tony" item2 = ItemClass() item2.name = "Mike" # add these to top class myTop.items.append(item1) myTop.items.append(item2) # up until this point, access class members is effortless as the # IDE (Eclipse)

Objective-c syntax for 2d array instance variable

随声附和 提交于 2019-12-11 09:04:26
问题 Usually I treat instance variables in Objective-c like this: @interface MyClass : NSObject @property (nonatomic, retain) NSMutableArray *mutableArray; @end @implementation MyClass @synthesize mutableArray; - (id) init { if((self = [super init])) { self.mutableArray = [NSMutableArray array]; } return self; } - (void) dealloc { [mutableArray release]; [super dealloc]; } @end I feel pretty comfortable w/ the above syntax. However I'm not so comfortable w/ the syntax for a 2D array instance

Difference between accessing static instance variables using the keyword this and Class name

一曲冷凌霜 提交于 2019-12-11 04:15:49
问题 I have got the following java class. When I am calling the login method in my constructor, I access the static instance variable username using the class name, and the static instance variable password using the keyword this . My question is what is the difference between the two approaches? Which one should be used in what situation? public class MyClass { private Main main; private static String username = "mylogindetails"; private static String password = "mypassword"; public MyClass(){

Strange values in an int array instance variable in Objective-C

心不动则不痛 提交于 2019-12-11 01:53:26
问题 I looked for similar topics but no luck so far, so here it goes: In an Objective-C class I declared an int pointer instance variable to hold an array of int : @interface MyList : NSObject { int index; // A simple int to hold an index reference NSString *name; // The name of the list int *bookList; // A pointer to an int array that holds a list of numbers } @property (nonatomic) int index; @property (nonatomic, copy) NSString *name; @property (nonatomic) int *bookList; @end I tested this as

Difference between the terms “Instance variable” and “variables declared in Interfaces”

爷,独闯天下 提交于 2019-12-10 18:58:47
问题 I was reading about Interfaces in a Book and I came upon this Line that confused me. Interfaces are syntactically similar to classes, but they lack instance variables. As far as I know about Interfaces , we can define variables inside an Interface which are by default final . My question is, What does that Line mean? and What is the Difference between an Instance Variable and the Variable defined in the Interface ?? 回答1: My question is, What does that Line mean? Amongst other things, it means