问题列表 - 第20264页

如何强制实例化C++模板的特定实例?

见标题.我有一个模板.我想强制模板的特定实例进行实例化.我该怎么做呢?

更具体地说,您可以强制抽象模板类进行实例化吗?


我可能会详细说明,因为我有同样的问题.在我的情况下,我正在构建一个库,一些模板实现很大,包含很多东西,但只生成几种类型.我想在库中编译它们并导出所有方法,但不包括带代码的头文件.

即:

template<class T>
OS_EXPORT_DECL class MyTmpl
{
    T *item1;
public:
    inline T *simpleGetT() { return(item1); } /* small inline code in here */ } 
    T *doSomeReallyBigMergeStuff(T *b); // note only declaration here
};

// *** implementation source file only seen inside library

template<class T>
MyTmpl<T>::doSomeReallyBigMergeStuff(T *b)
{
    ... a really big method, but don't want to duplicate it, 
        so it is a template ...
}
Run Code Online (Sandbox Code Playgroud)

我当然可以引用库中的所有方法来强制它们进行编译和导出,但是不希望向库添加不需要的代码,比如项的参数格式和调用它们的代码等.

????? 具体来说,我正在为多个版本的MSC和GCC以及英特尔编译器构建库.

c++ templates instantiation

49
推荐指数
2
解决办法
3万
查看次数

Android SDK Camera API演示崩溃

Android SDK有一个用于使用相机预览的API演示.但是,这给了我模拟器中的运行时异常.我在带有10.6的Mac上运行Eclipse

这是我抓住代码的链接:

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html

camera android android-emulator

3
推荐指数
1
解决办法
2万
查看次数

在课堂内,调用私人会员或其公共财产是否更好?

这是我在代码中一直在努力解决的问题.假设我们有以下代码:

public class MyClass {
    private string _myVariable;

    public string MyVariable {
        get { return _myVariable; }
        set { _myVariable = value; }
    }

    public void MyMethod() {
        string usingPrivateMember = _myVariable; // method A
        string usingPublicProperty = MyVariable; // method B
    }
}
Run Code Online (Sandbox Code Playgroud)

哪种方式更正确 - 方法A还是B?我总是对此感到不满.方法A似乎会快一点,因为它不需要在获取真实变量之前访问属性.但是,方法B更安全,因为如果MyVariable的getter添加了业务逻辑,即使没有当前的业务逻辑,也可以通过调用它来保证安全.

普遍的共识是什么?

c# variables properties

11
推荐指数
1
解决办法
349
查看次数

NSIS和PHP之间的Blowfish加密消息

对于我正在进行的项目,我需要使用Blowfish以跨NSIS和PHP的兼容方式加密和解密字符串.

目前我正在使用NSIS 的Blowfish ++插件mcryptPHP 的库.问题是,我不能让他们两个产生相同的输出.

让我们从NSIS Blowfish ++插件开始.基本上API是:

; Second argument needs to be base64 encoded
; base64_encode("12345678") == "MTIzNDU2Nzg="

blowfish::encrypt "test@test.com***" "MTIzNDU2Nzg="
Pop $0 ; 0 on success, 1 on failure
Pop $1 ; encrypted message on success, error message on failure
Run Code Online (Sandbox Code Playgroud)

没有提到它是CBC,ECB,CFB等,而且我对Blowfish不够熟悉,无法通过阅读大部分未记录的来源来讲述.我认为它是ECB,因为PHP文档mcrypt告诉我ECB不需要IV.

我还通过阅读源代码了解到Blowfish ++插件将Base64解码第二个加密参数(我不知道为什么).它还返回Base64编码的字符串.

对于PHP方面,我基本上使用此代码进行加密:

$plainText = "test@test.com***";
$cipher = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_ECB, '');   
$iv = '00000000';  // Show not be used anyway.
$key = "12345678";

$cipherText = …
Run Code Online (Sandbox Code Playgroud)

php c++ encryption blowfish nsis

1
推荐指数
1
解决办法
1721
查看次数

如何在Scala中使用函数参数模拟方法?

我正在尝试模拟一个带有call-by-name参数的方法调用:

import org.scalatest.WordSpec
import org.scalatest.mock.MockitoSugar
import org.mockito.Mockito._
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner

trait Collaborator {
   def doSomething(t: => Thing)
}

trait Thing

@RunWith(classOf[JUnitRunner])
class Test extends WordSpec with MockitoSugar {
   "The subject under test" should {
      "call the collaborator" in {
         // setup
         val m = mock[Collaborator]
         val t = mock[Thing]

         // test code: this would actually be invoked by the SUT
         m.doSomething(t)

         // verify the call
         verify(m).doSomething(t)
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

我主要对Mockito感兴趣,因为我正在使用它,但我有兴趣看看是否有任何主要的模拟框架能够进行这种测试.测试在运行时在线上失败,verify出现类似的错误

Argument(s) are different! Wanted:  
collaborator.doSomething(  
   ($anonfun$apply$3) <function> …
Run Code Online (Sandbox Code Playgroud)

scala mocking

20
推荐指数
1
解决办法
1万
查看次数

如何更新表中的值

我有以下select语句.我想将ContactAssociate的值从'Bob'更新为'Jane'.是否有可能做到这一点?

SELECT TOP (1500) ContactID, ContactNotes, 
  ContactAssociate, ContactAppointment
FROM  
  tb_Contact
WHERE 
 (ContactAssociate = 'Bob') AND 
 (ContactAppointment = 0)
Run Code Online (Sandbox Code Playgroud)

sql t-sql sql-server

1
推荐指数
1
解决办法
600
查看次数

当方向改变时,视图控制器对我做了什么?

一个简单的iphone程序,由项目模板基于视图的应用程序生成,带有几个按钮,我添加了以下代码:

- (void) showInfo: (UIView *) view {
    NSLog(@"view bounds  %6.2f %6.2f %6.2f %6.2f", view.bounds.origin.x, view.bounds.origin.y, view.bounds.size.width, view.bounds.size.height);
    NSLog(@"view frame   %6.2f %6.2f %6.2f %6.2f", view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height);
    NSLog(@"view center  %6.2f %6.2f", view.center.x, view.center.y);
}

- (BOOL)shouldAutorotateToInterfaceOrientation: UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (void)willRotateToInterfaceOrientation: (UIInterfaceOrientation) toInterfaceOrientation duration:(NSTimeInterval) duration {
    switch(toInterfaceOrientation) {
        case UIInterfaceOrientationPortrait:
            [self showInfo: self.view];
            break;
        case UIInterfaceOrientationLandscapeLeft:
            [self showInfo: self.view];
            break;
        case UIInterfaceOrientationLandscapeRight:
            [self showInfo: self.view];
            break;
    }
}

- (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation) fromInterfaceOrientation {
    switch(fromInterfaceOrientation) …
Run Code Online (Sandbox Code Playgroud)

iphone

4
推荐指数
1
解决办法
773
查看次数

125
推荐指数
4
解决办法
6万
查看次数

在调用b.form.submit()之后,我可以让我的mechanize.Browser实例保持在同一页面上吗?

在Python的mechanize.Browser模块中,当您提交表单时,浏览器实例将转到该页面.对于这一个请求,我不希望这样; 我希望它只是留在当前的页面上并在另一个对象中给出响应(用于循环目的).有人知道这么做吗?

编辑:嗯,所以我有这种与ClientForm.HTMLForm.click()的工作,它返回一个urllib2请求,但我需要来自mechanize的cookiejar的cookie才能在我的urllib2.urlopen请求中使用.机械化中是否有一种方法可以让我像urllib2一样发送请求,但是会导入cookie?

python screen-scraping mechanize

3
推荐指数
1
解决办法
1012
查看次数

美国政府API?

我正在开发一个应用程序,为人们提供一种简单的方法来跟踪账单状态[和其他各种政治信息].我喜欢OpenCongress的想法,例如,当它导航政治过程时,它会显示有关立法的摘要信息,但如果它有基于标签的搜索系统和其他一些丰富的搜索选项,以及更方便的话,我会喜欢它.可访问的投票历史和期限信息.虽然他们现在有JavaScript小工具,显示您选择的账单的当前状态,我认为在这方面可以做更多.

我不知道他们在哪里获得他们的数据,虽然他们有自己的API,但我不知道是否坚持使用它是实现我想象的最佳方式.对于所有透明度的宣传,对我来说,政府提供的数据,甚至如何找到它都不是很明显!

那么,有没有人知道任何有关美国立法,立法者(如投票历史),机构和/或即将举行的选举的信息的良好API ?(或者,如果您认为它非常有趣,请随意发布与美国政治相关的任何其他API.)

language-agnostic api resources egovernment

26
推荐指数
1
解决办法
1081
查看次数