我有一个集合实现了一个扩展IList <T>和List的接口.
public Interface IMySpecialCollection : IList<MyObject>, IList { ... }
Run Code Online (Sandbox Code Playgroud)
这意味着我有两个版本的索引器.
我希望使用通用实现,所以我通常实现它:
public MyObject this[int index] { .... }
Run Code Online (Sandbox Code Playgroud)
我只需要IList版本进行序列化,所以我明确地实现它,以保持隐藏:
object IList.this[int index] { ... }
Run Code Online (Sandbox Code Playgroud)
但是,在我的单元测试中,以下内容
MyObject foo = target[0];
Run Code Online (Sandbox Code Playgroud)
导致编译器错误
以下方法或属性之间的调用不明确
我对此感到有些惊讶; 我相信我以前做过它并且工作正常.我在这里错过了什么?如何让IList <T>和IList在同一个界面中共存?
编辑 IList <T> 没有实现IList,我必须实现IList进行序列化.我对变通办法不感兴趣,我想知道我缺少什么.
再次编辑:我不得不从界面中删除IList并将其移到我的课堂上.我不想这样做,因为实现接口的类最终将被序列化为Xaml,这需要集合来实现IDictionary或IList ...
请考虑以下代码:
#include <vector>
struct A
{
explicit A(int i_) : i(i_) {}
int i;
};
int main()
{
std::vector<int> ints;
std::vector<A> As(ints.begin(), ints.end());
}
Run Code Online (Sandbox Code Playgroud)
上面应该编译吗?由于构造函数被标记,我的感觉是它不应该explicit
.
Microsoft Visual C++同意,给出一个明确的错误消息: cannot convert from 'int' to 'const A'; Constructor for struct 'A' is declared 'explicit'
但是,使用Comeau的在线编译器,代码编译成功.
哪个是对的?
编辑:
有趣的是,更改vector
为set
(在添加operator <
到A之后)会导致两个编译器都出错.
然而,改变vector<int>
以map<int, int>
及vector<A>
对map<A, A>
原因两种编译器接受代码!
给出2个班级:
...
class Grades{
public:
Grades(int numExams) : _numExams(numExams){
_grdArr = new double[numExams];
}
double GetAverage() const;
...
private: // The only data members of the class
int _numExams;
double *_grdArr;
};
class Student{
public:
Student(Grades g) : _g(g){
}
...
private: // The only data members of the class
Grades _g;
};
...
Run Code Online (Sandbox Code Playgroud)
而且,一个简短的主程序:
int main(){
int n = 5; // number of students
Grades g(3); // Initial grade for all students
// ... Initialization of g – assume …
Run Code Online (Sandbox Code Playgroud) 我们有几百个测试类,其中几十个标有以下属性:[TestFixture] [Explicit] [Category("IntegrationTests")]因此它们只能在我们的夜间自动构建中运行.其余的TestFixtures没有指定类别(也没有标记为Explicit).
这是我们为执行测试而运行的NAnt任务:
<nunit2>
<test>
...
<categories>
<include name="IntegrationTests" />
</categories>
...
</test>
</nunit2>
Run Code Online (Sandbox Code Playgroud)
当然,这不会执行任何未分类的测试.
我希望能够做到这样的事情:
<nunit2>
<test>
...
<categories>
<include name="*" />
<include name="IntegrationTests" />
</categories>
...
</test>
</nunit2>
Run Code Online (Sandbox Code Playgroud)
所有未分类的测试都将与集成测试一起运行.这可能吗?如果是这样,语法是什么?
(注意:我正在寻找一个NAnt解决方案,如上所述,或NUnit命令行解决方案.我当然可以使用不同的选项运行NUnit两次,或者在我的所有TestFixtures上放置类别.这些是我的解决方法如果必须,可以使用,但是能够直接指定未分类的测试会更酷.)
我正在尝试使用显式意图在我的Android应用程序中显示MapView.虽然我没有看到我的代码有任何问题,但是当我尝试开始我的活动时,我不断收到"NoClassDefFoundError".基本上,从我的主要活动(SetCriteria),我在用户按下按钮时创建显式意图:
Log.i(TAG, "Showing map..");
try{
Intent intentMap = new Intent(view.getContext(), AddLocation.class);
startActivity(intentMap);
}catch(Throwable ex) {
Log.e(TAG, "Error occured while trying to display map", ex);
}
Run Code Online (Sandbox Code Playgroud)
我的LogCat显示:
java.lang.NoClassDefFoundError: com.adm.AddLocation
...
Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
Run Code Online (Sandbox Code Playgroud)
我的清单看起来像这样:
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher_red">
<uses-library android:name="com.google.android.maps"/>
<activity android:name=".SetCriteria"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AddLocation"
android:label="@string/add_location">
</activity>
</application>
Run Code Online (Sandbox Code Playgroud)
我只有一个包:com.adm.那可能是什么错?通过使用Intent(Intent.ACTION_VIEW,uri)启动地图没有问题,但我希望我的特定活动处理地图.
我正在尝试NSView
使用核心动画进行滑动.我想我需要使用显式动画而不是依赖于类似的东西[[view animator] setFrame:newFrame]
.这主要是因为我需要设置动画委托才能在动画结束后采取行动.
我使用动画师工作得很好,但正如我所说,我需要在动画结束时收到通知.我的代码目前看起来像:
// Animate the controlView
NSRect viewRect = [controlView frame];
NSPoint startingPoint = viewRect.origin;
NSPoint endingPoint = startingPoint;
endingPoint.x += viewRect.size.width;
[[controlView layer] setPosition:NSPointToCGPoint(endingPoint)];
CABasicAnimation *controlPosAnim = [CABasicAnimation animationWithKeyPath:@"position"];
[controlPosAnim setFromValue:[NSValue valueWithPoint:startingPoint]];
[controlPosAnim setToValue:[NSValue valueWithPoint:endingPoint]];
[controlPosAnim setDelegate:self];
[[controlView layer] addAnimation:controlPosAnim forKey:@"controlViewPosition"];
Run Code Online (Sandbox Code Playgroud)
这在视觉上有效(并且我在最后得到通知),但看起来实际的controlView没有被移动.如果我使窗口刷新,controlView将消失.我试过更换
[[controlView layer] setPosition:NSPointToCGPoint(endingPoint)];
Run Code Online (Sandbox Code Playgroud)
同
[controlView setFrame:newFrame];
Run Code Online (Sandbox Code Playgroud)
这确实会导致视图(和图层)移动,但它会破坏某些东西,以至于我的应用程序很快就会因为seg故障而死亡.
大多数显式动画的例子似乎只是在移动a CALayer
.必须有一种方法来移动NSView
并且还能够设置代理.任何帮助,将不胜感激.
在Youtube上的GoogleTechTalks视频中,Bjarne Stroustrup谈到即将推出的C++ 0x标准.在视频中,他提到了以下示例:
#include <iostream>
struct Sick
{
Sick(double d) { std::cout << d << "\n"; }
explicit Sick(int i) { std::cout << i << "\n"; }
};
int main()
{
Sick s1 = 2.1;
Sick s2(2.1);
}
Run Code Online (Sandbox Code Playgroud)
他是否意味着将explicit
关键字放在之前Sick(double)
而不是Sick(int)
,以突出显示与某些上下文中的隐式转换相关的问题?
我对以下代码有一些问题.我想将一个字符串显式化为一个对象,这是完全正常的,但是,如果此对象是泛型类的一部分,则失败并出现以下错误异常:"无法转换类型为'System.String'的对象'输入'test.B'".即使我已经重载了该方法.
using System;
using System.Collections.Generic;
namespace test {
class Program {
static void Main(string [] args) {
// These two cast perfectly fine.
B x = (B) "abc";
C y = (C) "def";
A <B> a = new A<B>();
a.b();
A <C> b = new A<C>();
b.b();
}
}
class A<T> {
public List <T> a = new List<T>();
public void b() {
// Unable to cast object of type 'System.String' to type 'test.B'
this.a.Add ((T) (object) "abc");
this.a.Add ((T) …
Run Code Online (Sandbox Code Playgroud) 当我在iTunes中查看我购买的音乐时,歌曲列表旁边的红色显式框会显示明确的歌曲.即,您在购买歌曲时看到的显式标签会传递到iTunes资料库.歌曲itunes标记为干净的歌曲也是如此.我真的希望能够识别我的ios应用程序中明确显示的任何歌曲,但是我找不到任何关于标签是否通过其他歌曲信息(MPMediaItemProperty)传递到ios设备的资源,如果是这样的话得到它(我无休止地搜索!)有些歌曲在其标题的末尾包含"[Explicit]",但这只是一些歌曲的情况,而不是所有.有人知道标签是否存在且可从Objective读取-C代码?
explicit ×10
c++ ×3
c# ×2
constructor ×2
generics ×2
.net ×1
android ×1
avfoundation ×1
c++11 ×1
casting ×1
categories ×1
cocoa ×1
delegates ×1
implicit ×1
interface ×1
ios ×1
iterator ×1
maps ×1
mpmediaquery ×1
nant ×1
nant-task ×1
nsview ×1
nunit ×1
objective-c ×1
operators ×1