outer-classes

Get address of a non-POD object from within a data member, which is a single-use nested class

﹥>﹥吖頭↗ 提交于 2019-12-04 19:20:28
I'll start with some code: class myNonPODClass { public: virtual ~myNonPODClass() {} class { public: myNonPODClass* GetContainer() { return (myNonPODClass*)((int8_t*)(this) - offsetof(myNonPODClass, member)); } } member; }; Obviously, this is a contrived example. The code compiles fine, but I'm worried about the "Offset of on non-POD type 'myNonPODClass'". Is there a better way to do essentially the same thing WITHOUT having to pass the myNonPODClass pointer into the nested anonymous classes constructor (or similar)? "member" must be ready to go without any initialization. Is it possible?

Getting Reference to Calling Activity from AsyncTask (NOT as an inner class)

江枫思渺然 提交于 2019-12-04 06:21:28
Is it at all possible, from within an AsyncTask that is NOT an inner class of the calling Activity class, to get a reference to the instance of Activity that initiated execution of the AsyncTask? I am aware of this thread , however it doesn't exactly address how to reference the calling Activity. Some suggest passing a reference to the Activity as a parameter to the AsyncTask constructor, however, it's reported that doing so will always result in a NullPointerException. So, I'm at a loss. My AsyncTask provides robust functionality, and I don't want to have to duplicate it as an inner class in

Java Inner Class extends Outer Class

牧云@^-^@ 提交于 2019-12-03 06:55:41
There are some cases in Java where an inner class extends an outer class. For example, java.awt.geom.Arc2D.Float is an inner class of java.awt.geom.Arc2D, and also extends Arc2D. (c.f. http://download.oracle.com/javase/6/docs/api/java/awt/geom/Arc2D.Float.html ) Also, sun.org.mozilla.javascript.internal.FunctionNode.Jump extends sun.org.mozilla.javascript.internal.Node, which is a superclass of FunctionNode. (sorry... cannot find a link to the javadoc) To me, this seems odd. Could you then create these? new Arc2D.Float.Float() //n.b. I couldn't get this to compile in Intellij IDEA; new

how to restrict setting a property of innerclass just from the outer class in c#

旧时模样 提交于 2019-12-02 23:00:27
问题 I have the nub of the code like this: public class OuterClass { public static InnerClass GetInnerClass() { return new InnerClass() { MyProperty = 1 }; } public class InnerClass { public int MyProperty { get; set; } } } what is the solution to property named MyProperty just be settable from the InnerClass and the OuterClass , and out of these scopes, MyProperty just be readonly 回答1: There is no protection level for that. internal is the tightest you can use, which is limited to files in the

how to restrict setting a property of innerclass just from the outer class in c#

爱⌒轻易说出口 提交于 2019-12-02 13:09:34
I have the nub of the code like this: public class OuterClass { public static InnerClass GetInnerClass() { return new InnerClass() { MyProperty = 1 }; } public class InnerClass { public int MyProperty { get; set; } } } what is the solution to property named MyProperty just be settable from the InnerClass and the OuterClass , and out of these scopes, MyProperty just be readonly There is no protection level for that. internal is the tightest you can use, which is limited to files in the same assembly. If you cannot make it a constructor parameter as has been proposed, you could use an interface: