rails 3: clarification needed on which controllers are needed for HABTM relationships
Date : March 29 2020, 07:55 AM
this will help I think that one way to do it could be the following: I would accept the event to have the user as a nested resource this way: class Event < ActiveRecord::Base
has_many :users
accepts_nested_attributes_for :events
end
class ApplicationController < ActionController::Base
def add_user_to_event
@event = Event.find(params[:event])
@user = User.find(params[:user])
@event.users << @user
@event.save
end
end
|
Some clarification needed in the struct pointers
Date : March 29 2020, 07:55 AM
With these it helps The problem here is that the "->" operator is binding more tightly than the "*" operator. So your first statement: // what you have written
*root->link;
// what you're getting - bad
*(root->link);
// what you want - good
(*root)->link;
|
On C++ pointers and references, clarification needed
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further void foo (int &something) // Will accept an address of something void foo (something); // "something" must be a variable
|
(C++) Clarification needed about accessing derived functions from a vector of pointers
Tag : cpp , By : user161380
Date : March 29 2020, 07:55 AM
Hope this helps It is hard to follow what exactly do you mean, but I think you refer to automatic allocation getting destroyed. Something among the lines of: // WARNING: incorrect code
std::vector<base*> v;
for (int i = 0; i < 10; i++) {
Derived d;
v.push_back(&d);
}
v[0]->foo();
// WARNING: incorrect code
std::vector<base*> v;
for (int i = 0; i < 10; i++) {
Derived* d = new Derived();
v.push_back(d);
delete d;
}
v[0]->foo();
|
Pass vector of pointers by reference and replace a vector of void* pointers
Date : March 29 2020, 07:55 AM
|