[winrt]Unable to initialize the base class of projected type - windows-runtime

i'm a newer to cpp/winrt, i use implements_type and base_type to initialize the base class of projected type, but compile error.
namespace Velkhana
{
[default_interface]
unsealed runtimeclass Only{
Only(Object inner);
....
}
}
local class:
class Only2 : public winrt::implements<Only2, Velkhana::Only>
{
Only2() : implements_type(box_value(true)) {
}
};
this compile error: error C2664: 'winrt::implements<Only2,winrt::Velkhana::Only>::implements(const winrt::implements<Only2,winrt::Velkhana::Only> &)': cannot convert argument 1 from 'winrt::Windows::Foundation::IInspectable' to 'const winrt::implements<Only2,winrt::Velkhana::Only> &'
why can't i init base class in this case?
[Image](https://i.stack.imgur.com/oL9GH.png)
https://i.stack.imgur.com/oL9GH.png
I analyzed the source code, but don't find winrt::implements constructor, how local class initializes the grandparent class by implements_type ?
Is there any trick here?

Related

How to access protected method of Java jar file's class

I am using a Java command-line application (which is open-source) as a jar file for my jrubyonrails project. The main application is like following
public class Decoder extends Annotator {
public Decoder() {
super();
}
public static void main(String[] args) {
... // Do something that I don't want
myDesiredMethod();
... // And some other thing
}
...
}
There are many steps which I want to skip, I only want myDesiredMethod function. And it is a protected method from the parent Annotator class.
public class Annotator extends Helper {
...
protected SomeClass myDesiredMethod(boolean reMap) throws Exception { ... }
...
}
Annotator class does not have any public constructor so that I cannot:
ann = Annotator.new
It raises this error: TypeError: no public constructors for Annotator.
Then I try to implement another class which inherits Annotator in order to access myDesiredMethod. This is the jruby code I have tried so far
require 'java'
require 'decoder.jar'
java_import java.util.ArrayList
java_import java.lang.StringBuilder
module MyModule
class RuDecoder < Annotator
include_package 'com.decoder'
def self.my_method
myDesiredMethod
end
end
It returns the error: NoMethodError: undefined method 'myDesiredMethod' for MyModule::RuDecoder:Class. Seems jruby does not look for the method of the parent class.
Is there any solution in my case, I don't want to rebuild the java library to jar and manually put it into my program every time it has an update.
Turns out that I made thing over-complicated. I can call the default constructor of Annotator as following:
constructors = Annotator.java_class.declared_constructors.first
constructors.accessible = true
annotator = constructors.new_instance.to_java
And use simple call myDesiredMethod: annotator.myDesiredMethod

call one constructor from another constructors in one class

I've encountered the following question online.
If we call one constructor from another in a class, what will happen?
Can anyone give me some hints?
in java also its possible with the power of the this keyword. check out the example given below.
public class A {
public A() {
//this("a");
System.out.println("inside default Constructor");
}
public A(String a){
this();
System.out.println("inside Constructor A");
}
}
This concept is called constructor chaining. If it's c# i found this saying it's possible Is nesting constructors (or factory methods) good, or should each do all init work
This example from MSDN clarifies it
To add delegating constructors, constructor (. . .) : constructor (. . .) syntax is used.
class class_a {
public:
class_a() {}
// member initialization here, no delegate
class_a(string str) : m_string{ str } {}
// can’t do member initialization here
// error C3511: a call to a delegating constructor shall be the only member-initializer
class_a(string str, double dbl) : class_a(str) , m_double{ dbl } {}
// only member assignment
class_a(string str, double dbl) : class_a(str) { m_double = dbl; }
double m_double{ 1.0 };
string m_string;
};
Read answers from Can I call a constructor from another constructor (do constructor chaining) in C++? too.

Flash Namespace error 1004: Namespace was not found or is not a compile-time constant

I have a class: myClass_x.as with contents:
package com.a.b.c
{
public namespace myClass_x = "com.a.b.c:myClass_x";
}
I have a second class: myClass_y with function:
myClass_x function myFunction(param1:int, param2:int, param3:int) : void {...}
I have a third class: myClass_z with function:
override myClass_x function myFunction(param1:int, param2:int, param3:int) : void {...}
When I try to compile, I get error:
1004: Namespace was not found or is not a compile-time constant.
Any ideas what's going wrong?
Are you sure you've imported the namespace at the top of each class?
import com.a.b.c.myClass_x;
You can also get your error if the filename does not exactly match the namespace name.
Above your class block add the line use namespace myClass_x;

Using constants as default parameter values in interfaces: IDE okay but mxmlc fails?

This code seems to compile fine in the IDE, but the command-line compiler (SDK 4.5 mxmlc.exe) reports "Parameter initializer unknown or is not a compile-time constant."
senocular gives a good explanation and a maybe-workaround, but I'm hoping for something more elegent (like a command-line instruction).
package {
public class Constants {
public static const CONSTANT : int = 0;
}
}
package {
public interface IInterface {
function foo( param : int = Constants.CONSTANT ) : void;
}
}
package
{
public class Concrete implements IInterface
{
public function foo(param:int=Constants.CONSTANT):void
{
}
}
}
According to Senocular, it's all about the compilation order. There's no explicit way to set this order.
You could define inline constants using the define compiler option to avoid this problem.
Another way would be to create a library containing the constants. Libraries are included before user classes.
To create a library use the component compiler:
compc -output lib\Constants.swf -source-path src -include-classes Constants
When compiling the application, include that library:
mxmlc -include-libraries lib\Constants.swf -- src\Main.as
Just don't forget to recompile the library when the constants change, or use a build script that takes care of that.
A short comment on the example code:
The interface doesn't need to use that constant, any value will do and have the same effect on implementing classes.
Programming AS3 - Interfaces
A method that implements such a function declaration must have a default parameter value that is a member of the same data type as the value specified in the interface definition, but the actual value does not have to match.

Error instantiating object in Castle Windsor

I do not understand the error I am getting as listed at the bottom of this question. Why is the container trying to cast the object, especially if the compiler is doing it without error? I am using v2.0.0.5642.
I’m sure it’s in the configuration, but I am lost. I would really appreciate any help.
<component id="cipherMaster" type="Demo.View.UserControls.CipherMaster, Demo.View" />
<component id="cipherVariation" service="Demo.View.UserControls.CipherMaster, Demo.View"
type="Demo.View.UserControls.CipherVariation, Demo.View" />
<component id="presenterVariation" service="Demo.Model.Interfaces.IDemoTypePresenter, Demo.Model"
type="Demo.Presenter.PresenterVariation, Demo.Presenter" >
<cipherPanel>${cipherVariation}</cipherPanel>
</component>
namespace Demo.Presenter
{
public class PresenterCipherMaster : IDemoTypePresenter
{
...
}
}
namespace Demo.Presenter
{
public class PresenterVariation : PresenterCipherMaster
{
private readonly CipherVariation _variation;
public PresenterVariation(IMasterDemo view, CipherMaster cipherPanel, FeaturesVariation features,
IEncryptionEngine engine):base(view, cipherPanel, features, engine)
{
_variationLog = new List<CipherVariationLog>();
_variation = (CipherVariation) cipherPanel; //<<< Cast error points here line 18
...
}
}
}
public static class IocContainer
{
public static T Resolve<T>(string key)
{
T presenter = Container.Resolve<T>(key); //<<< Error occurs here
return presenter;
}
}
namespace Demo.View.UserControls
{
public partial class CipherMaster : UserControl
{
...
}
}
namespace Demo.View.UserControls
{
public partial class CipherVariation : CipherMaster
{
...
}
}
=====================
Castle.MicroKernel.ComponentActivator.ComponentActivatorException was unhandled
Message="ComponentActivator: could not instantiate Demo.Presenter.PresenterVariation"
Source="Castle.MicroKernel"
StackTrace:
...
InnerException: System.Reflection.TargetInvocationException
Message="Exception has been thrown by the target of an invocation."
Source="mscorlib"
StackTrace:
...
InnerException: System.InvalidCastException
Message="Unable to cast object of type 'Demo.View.UserControls.CipherMaster' to type 'Demo.View.UserControls.CipherVariation'."
Source="Demo.Presenter"
StackTrace:
at Demo.Presenter.PresenterVariation..ctor(IMasterDemo view, CipherMaster cipherPanel, FeaturesVariation features, IEncryptionEngine engine) in E:\Development\MainStreamDemo\Demo.Presenter\PresenterVariation.cs:line 18
InnerException:
I've seen situations where Castle resolves against the other registered services first, and then uses the parameters you specify. In this case since you are using a concrete type as the argument (CipherMaster) and it is registered, it's probably using the registered component.
I would try either creating an interface for the two controls to implement or just changing the type on the constructor to just "Object" or "UserControl" so that it's not a registered type.