目前,我有一些代码如下
template<typename Type>
Type* getValue(std::string name, bool tryUseGetter = true)
{
if(tryUseGetter)
{
if(_properties[name]->hasGetter)
{
return (Type*)_properties[name]->getter();
}
return (Type*)_properties[name]->data;
}
else
{
return (Type*)_properties[name]->data;
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法让tryUseGetter成为编译时开关?即将它移动到模板声明,所以它类似于此
template<typename Type, bool tryUseGetter = true>
...
Run Code Online (Sandbox Code Playgroud)
谢谢.
我目前正在实现一个基于HTML画布的webapp,它具有平移功能.有没有办法使用辅助缓冲区来保持当前可见的区域,所以当我平移时,我不需要重绘整个画布,只需绘制新的可见区域?
根据exec引用,对exec(或一般的堆栈检查vararg函数)的调用在(char*)NULL参数列表的末尾需要一个aka 0.然而,海湾合作委员会抱怨以下代码
char cmdFullPath[4096]; //yes this 4096 thing is bad coding practice
...
execl(cmdFullPath, (char*)NULL);
//warning: not enough variable arguments to fit a sentinel
Run Code Online (Sandbox Code Playgroud)
谁知道什么是错的?
abstract class A<T> where T:A<T>
{
public event Action<T> Event1;
}
class B : A<B>
{
//has a field called Action<B> Event1;
}
Run Code Online (Sandbox Code Playgroud)
有没有更优雅的方式来做到这一点?我希望基类中的东西(事件等)能够使用子类的类型.
是否有非hacky(即没有汇编,...)方式使用boost函数来创建非静态类方法的回调?
目前用于静态方法:
list<function<void (LuaState&)> > _callbacks;
Run Code Online (Sandbox Code Playgroud)
我正在思考一些事情
list<tuple<function<void (void *, LuaState&)>, void*> _callbacks;
Run Code Online (Sandbox Code Playgroud)
但是增强功能不喜欢那些void*.
是否有以下的Visual C++版本(在GCC中)?
__builtin_return_address __builtin_frame_address参考 - http://gcc.gnu.org/onlinedocs/gcc/Return-Address.html
如果没有,有没有办法模仿它们?
谢谢.
当用于表示0-> 1范围内的数据时哪一个更精确?或者没有精确度差异?
可能只是某种严重疏忽,但我没有在消息循环中收到任何WM_SIZE消息.但是,我确实在WndProc中收到了它们.我以为windows循环向WndProc发送了消息?
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
switch(message)
{
// this message is read when the window is closed
case WM_DESTROY:
{
// close the application entirely
PostQuitMessage(0);
return 0;
} break;
case WM_SIZE:
return 0;
break;
}
printf("wndproc - %i\n", message);
// Handle any messages the switch statement didn't
return DefWindowProc (hWnd, message, wParam, lParam);
}
Run Code Online (Sandbox Code Playgroud)
......现在消息循环......
while(TRUE)
{
// Check to see if any messages are waiting in the queue
if(PeekMessage(&msg, …Run Code Online (Sandbox Code Playgroud) 有没有办法在C++中执行以下操作
template<typename TAnimal>
bool can_eat(TAnimal& animal) where bool TAnimal::IsAlive() exists
{
return !animal.IsAlive();
}
//...
Duck duck;
assert(can_eat(duck) == true); //compiles
Wood wood;
can_eat(wood); // fails to compile because wood doesn't have IsAlive()
Run Code Online (Sandbox Code Playgroud)
在我看来,显式接口使得函数期望更清楚.但是,我不想创建一个实际的接口类(非常繁琐).
我是一个Ruby新手(4天前开始,嘿韵!)并决定编写一个简单的小工具,用于娱乐/学习.以下代码是结果.它工作正常,但我真的很感谢来自一些更有经验的Ruby开发人员的批评.我正在寻找关于风格,冗长和任何misc的评论.提示与技巧.
顺便说一句,我真的很想知道如何重写lambda递归更优雅.(ctrl-f代表'lambda recursion')
注意:这不是Ruby On Rails项目.这是Eve Online的一个小工具.
require 'rubygems'
require 'reve'
require 'yaml'
BASE_SKILLPOINTS = [0, 250, 1414, 8000, 45255, 256000]
def calc_remaining_sp(rank, from_level, to_level)
sp = BASE_SKILLPOINTS.map { |x| x * rank }
[sp[to_level] - sp[from_level], 0].max
end
def summarize_skills(user_id, api_key)
spec = YAML::load(File.open('ukc_skillsets.yaml'))
api = Reve::API.new user_id, api_key
#skill id => general skill info
skills_list = Hash[api.skill_tree.map { |x| [x.type_id, x] }]
api.characters.each { |char|
char_sheet = api.character_sheet :characterID => char.id
puts ""
puts "Character - #{char.name}"
puts …Run Code Online (Sandbox Code Playgroud) c++ ×6
gcc ×3
function ×2
templates ×2
boost ×1
c ×1
c# ×1
canvas ×1
class ×1
directx ×1
duck-typing ×1
exec ×1
g++ ×1
generics ×1
html ×1
javascript ×1
lambda ×1
methods ×1
optimization ×1
recursion ×1
ruby ×1
system-calls ×1
visual-c++ ×1
windows ×1
yaml ×1