花了很长时间在C#中开发,我注意到如果为了将它用作接口而声明一个抽象类,则无法实例化该抽象类的向量来存储子类的实例.
#pragma once
#include <iostream>
#include <vector>
using namespace std;
class IFunnyInterface
{
public:
virtual void IamFunny() = 0;
};
class FunnyImpl: IFunnyInterface
{
public:
virtual void IamFunny()
{
cout << "<INSERT JOKE HERE>";
}
};
class FunnyContainer
{
private:
std::vector <IFunnyInterface> funnyItems;
};
Run Code Online (Sandbox Code Playgroud)
声明抽象类向量的行在MS VS2005中导致此错误:
error C2259: 'IFunnyInterface' : cannot instantiate abstract class
Run Code Online (Sandbox Code Playgroud)
我看到一个明显的解决方法,即用以下内容替换IFunnyInterface:
class IFunnyInterface
{
public:
virtual void IamFunny()
{
throw new std::exception("not implemented");
}
};
Run Code Online (Sandbox Code Playgroud)
这是一个可接受的解决方案C++明智吗?如果没有,是否有像boost这样的第三方库可以帮我解决这个问题?
谢谢您阅读此篇 !
安东尼
我想向POSIXct对象添加1小时,但它不支持'+'.
这个命令:
as.POSIXct("2012/06/30","GMT")
+ as.POSIXct(paste(event_hour, event_minute,0,":"), ,"%H:%M:$S")
Run Code Online (Sandbox Code Playgroud)
返回此错误:
Error in `+.POSIXt`(as.POSIXct("2012/06/30", "GMT"), as.POSIXct(paste(event_hour, :
binary '+' is not defined for "POSIXt" objects
Run Code Online (Sandbox Code Playgroud)
如何为POSIXct对象添加几个小时?
当运行prorgam时,我似乎错过了一个库,当我启动项目的输出时,我在启动时遇到异常.
A first chance exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll
An unhandled exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll
Additional information: A procedure imported by 'my assembly, Version=xx.1.1.0, Culture=neutral, PublicKeyToken=7292581204d9e04a' could not be loaded.
'ScriptX.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', No symbols loaded.
Run Code Online (Sandbox Code Playgroud)
我的问题是:如何确定哪个库丢失,因为此时我无法看到传递给的值:
mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) + 0x3a bytes
Run Code Online (Sandbox Code Playgroud) 问题的第一部分是我正在尝试使用boost :: bimap,但是从文档中我不清楚如何定义双向多图.
问题的第二部分是我需要它是一个方向的地图和另一个方向的多个地图,这可以使用boost :: bimap来完成吗?
有没有人经历过这个或者能指出我正确的页面?
在实际环境中,使用gcc或MS Visual Studio,通过const引用传递大小相同或小于int的值类型是不是很糟糕?
即编写这样的函数是不好的:
void f(const bool& b);
Run Code Online (Sandbox Code Playgroud)
要么
void f(const char& c);
Run Code Online (Sandbox Code Playgroud)
而不是:
void f(bool b);
Run Code Online (Sandbox Code Playgroud)
要么
void f(char c);
Run Code Online (Sandbox Code Playgroud)
我问的原因是我没有看到在这些情况下传递参考的好处,但也许我错过了一些东西.
我有10个表,除了表名以外具有相同的结构.
我有一个sp(存储过程)定义如下:
select * from table1 where (@param1 IS NULL OR col1=@param1)
UNION ALL
select * from table2 where (@param1 IS NULL OR col1=@param1)
UNION ALL
...
...
UNION ALL
select * from table10 where (@param1 IS NULL OR col1=@param1)
Run Code Online (Sandbox Code Playgroud)
我用以下行调用sp:
call mySP('test') //it executes in 6,836s
Run Code Online (Sandbox Code Playgroud)
然后我打开了一个新的标准查询窗口.我刚刚复制了上面的查询.然后用'test'替换@ param1.
这在0,321秒内执行,比存储过程快20倍.
我重复更改了参数值,以防止缓存结果.但这并没有改变结果.SP比同等标准查询慢大约20倍.
请你帮我弄清楚为什么会这样?
有没有人遇到类似的问题?
我在Windows Server 2008 R2 64位上使用mySQL 5.0.51.
编辑:我正在使用Navicat进行测试.
任何想法对我都有帮助.
EDIT1:
我根据Barmar的回答做了一些测试.
最后,我改变了下面的sp,只有一行:
SELECT * FROM table1 WHERE col1=@param1 AND col2=@param2
Run Code Online (Sandbox Code Playgroud)
然后我首先执行标准查询
SELECT * FROM table1 WHERE col1='test' AND …Run Code Online (Sandbox Code Playgroud) 我用timeit获得了非常令人惊讶的结果,有人可以告诉我,如果我做错了吗?我使用的是Python 2.7.
这是文件speedtest_init.py的内容:
import random
to_count = [random.randint(0, 100) for r in range(60)]
Run Code Online (Sandbox Code Playgroud)
这些是speedtest.py的内容:
__author__ = 'BlueTrin'
import timeit
def test_init1():
print(timeit.timeit('import speedtest_init'))
def test_counter1():
s = """\
d = defaultdict(int);
for i in speedtest_init.to_count:
d[i] += 1
"""
print(timeit.timeit(s, 'from collections import defaultdict; import speedtest_init;'))
def test_counter2():
print(timeit.timeit('d = Counter(speedtest_init.to_count);', 'from collections import Counter; import speedtest_init;'))
if __name__ == "__main__":
test_init1()
test_counter1()
test_counter2()
Run Code Online (Sandbox Code Playgroud)
控制台输出是:
C:\Python27\python.exe C:/Dev/codility/chlorum2014/speedtest.py
2.71501962931
65.7090444503
91.2953839048
Process finished with exit code 0
Run Code Online (Sandbox Code Playgroud)
我认为默认情况下timeit()运行代码的1000000倍,所以我需要将时间除以1000000,但令人惊讶的是Counter慢于defaultdict().
这是预期的吗?
编辑:
使用dict也比defaultdict(int)更快: …
你好我有一个签名的功能
std :: string f(double x,double param1,double param2,double param3);
我想在std :: vector xvalues上为参数x调用它,使用std :: transform作为param1,param2和param3的特定值.
它相当于:
double param1(1.);
double param2(1.1);
double param3(1.2);
std::vector<std::string> results();
for (std::vector<double>::const_iterator it = xvalues.begin() ; it != xvalues.end() ; ++xvalues)
{
results.push_back(f(*it, param1, param2, param3);
}
Run Code Online (Sandbox Code Playgroud)
如何以更优雅的方式完成?
亲切的问候托尼