nested-class

Nested class of class template can be “incomplete”

删除回忆录丶 提交于 2021-02-08 21:49:17
问题 I'm at a loss as to how to explain why it is valid to create the member inner in the class template OuterTempl<T> whereas it is illegal to do so in the untemplated class Outer . // Non-template version struct Outer { struct Inner; Inner inner; // incomplete type (I get this) }; struct Outer::Inner { }; // Template version template<typename T> struct OuterTempl { struct InnerTempl; InnerTempl inner; // OK ... Huh!? }; template<typename T> struct OuterTempl<T>::InnerTempl { }; int main() { }

Nested Class .GetType()

笑着哭i 提交于 2020-01-24 03:09:24
问题 I noticed something curious when messing around with nested classes and outputting the name of the type to a console window. I was wondering if someone could explain it a bit for me. When calling GetType() on the main class, it returns what I would expect, which was the name of the class after the relevant namespaces. i.e. Namespace.Namespace.Classname However, when I call a function from within the enclosing class to return the type of the nested class I get the value returned as this:

instantiate inner broadcast receiver class

亡梦爱人 提交于 2020-01-16 08:49:07
问题 I just changed my external broadcast receiver class to my service since..some android method could not be used in static context. Now i receive an error Unable to instantiate activity ComponentInfo{com...}: java.lang.NullPointerException. How is it possible to fix? Below is my code for nested BroadcastReceiver class. public class ServiceX extends Service { private SharedPreferences settings = getSharedPreferences(PREFS, 0); private SharedPreferences.Editor editor = settings.edit(); private

C#: Is a private inner interface possible?

无人久伴 提交于 2020-01-12 19:09:47
问题 I have a generic class X<T> ; This class has a covariant part that I want to be able to access covariantly. So I factor it out into an interface IX<out T> . However, I want this interface to be visible only to the class itself, because it contains also methods that are ment to be private . I.e., inside the class itself, I can upcast to IX<T> and use it covariantly. E.g.: class X<T> : IX<T> { private interface IX<out T>{ // the private covariant interface void foo(); } // It grants access to

C#: Is a private inner interface possible?

房东的猫 提交于 2020-01-12 19:09:28
问题 I have a generic class X<T> ; This class has a covariant part that I want to be able to access covariantly. So I factor it out into an interface IX<out T> . However, I want this interface to be visible only to the class itself, because it contains also methods that are ment to be private . I.e., inside the class itself, I can upcast to IX<T> and use it covariantly. E.g.: class X<T> : IX<T> { private interface IX<out T>{ // the private covariant interface void foo(); } // It grants access to

How does one “override” an inner class in Scala?

风流意气都作罢 提交于 2020-01-12 14:49:32
问题 In the Scaladoc of class Enumeration#Val, I can read: "A class implementing the Value type. This class can be overridden to change the enumeration's naming and integer identification behaviour." I am puzzled: how do I override a class? Things like override class Val extends super.Val are not permitted. 回答1: There are no virtual classes in Scala (yet), so you can't write override class Val ... , and then be sure that invoking new Val will dynamically choose the right class for the new instance

Rails accepts_nested_attributes_for callbacks

狂风中的少年 提交于 2020-01-12 09:15:55
问题 I have two models Ticket and TicketComment , the TicketComment is a child of Ticket. ticket.rb class Ticket < ActiveRecord::Base has_many :ticket_comments, :dependent => :destroy, :order => 'created_at DESC' # allow the ticket comments to be created from within a ticket form accepts_nested_attributes_for :ticket_comments, :reject_if => proc { |attributes| attributes['comment'].blank? } end ticket_comment.rb class TicketComment < ActiveRecord::Base belongs_to :ticket validates_presence_of

Rails accepts_nested_attributes_for callbacks

自作多情 提交于 2020-01-12 09:15:55
问题 I have two models Ticket and TicketComment , the TicketComment is a child of Ticket. ticket.rb class Ticket < ActiveRecord::Base has_many :ticket_comments, :dependent => :destroy, :order => 'created_at DESC' # allow the ticket comments to be created from within a ticket form accepts_nested_attributes_for :ticket_comments, :reject_if => proc { |attributes| attributes['comment'].blank? } end ticket_comment.rb class TicketComment < ActiveRecord::Base belongs_to :ticket validates_presence_of

When to use nested class?

こ雲淡風輕ζ 提交于 2020-01-11 09:42:01
问题 The code below will find intersection of 2 lines and return the point object. If point is only ever going to be created by IntersectionOf2Lines class, should i make point a nested class ? If not then why not ? Thanks class Point { private final int x; private final int y; public Point(int x, int y) { this.x = x; this.y = y; } int getX() { return x; } int getY() { return y; } } public class IntersectionOf2Lines { public static Point calculateIntersection(Line line1, Line line2) { int x =

Overload operator<< for nested class template

寵の児 提交于 2020-01-11 08:51:09
问题 I have the following setup: template< class T > struct Foo { struct Bar { Bar ( const T &t ) : otherT_( t ) {} T otherT_; }; Foo ( const T &t ) : myT_( t ) {} T myT_; }; Now, I want to make instances of Foo< T >::Bar streamable to std::cout and friends. I tried this: template< class T > std::ostream& operator<< ( std::ostream &os, const typename Foo< T >::Bar &bar ) { os << "<bar: " << bar.otherT_ << ">"; return os; } But the following code does not compile: Foo< int > foo( 5 ); Foo< int >: