我使用Visual Studio 2012,并尝试使静态库UDT正常工作。不幸的是,我无法编译将UDT库链接到其自身的项目,我在Windows SDK标头中遇到有关类型或宏重新定义的159个奇怪的错误。
c:\program files\windows kits\8.0\include\shared\ws2def.h(96): warning C4005: 'AF_IPX' : macro redefinition
2> c:\program files\windows kits\8.0\include\um\winsock.h(452) : see previous definition of 'AF_IPX'
2>c:\program files\windows kits\8.0\include\shared\ws2def.h(136): warning C4005: 'AF_MAX' : macro redefinition
2> c:\program files\windows kits\8.0\include\um\winsock.h(471) : see previous definition of 'AF_MAX'
2>c:\program files\windows kits\8.0\include\shared\ws2def.h(173): warning C4005: 'SO_DONTLINGER' : macro redefinition
2> c:\program files\windows kits\8.0\include\um\winsock.h(394) : see previous definition of 'SO_DONTLINGER'
2>c:\program files\windows kits\8.0\include\shared\ws2def.h(217): error C2011: 'sockaddr' : 'struct' type redefinition
2> c:\program files\windows kits\8.0\include\um\winsock.h(477) : see declaration …
我需要使用peewee之类的ORM引擎来处理python应用程序中的SQLite数据库。但是,大多数此类库都提供如下语法来定义models.py:
import peewee
db = peewee.Database('hello.sqlite')
class Person(peewee.Model):
name = peewee.CharField()
class Meta:
database = db
Run Code Online (Sandbox Code Playgroud)
但是,在我的应用程序中,由于数据库文件名是从导入模块的模块导入后由外部代码提供的,因此我无法使用这种语法models.py。
如何在知道动态数据库文件名的情况下从其定义之外初始化模型?理想情况下,models.py不应该像普通的ORM那样完全包含“数据库”提及。
我有这门课:
class Model:
name = None
price = None
Run Code Online (Sandbox Code Playgroud)
Model像这样的简单实例:
name ; price
BMW 4-series ; 90
BMW Z4 ; 190
BMW X5 ; 220
Lamborghini Miura ; 910
Ferrari 458 Italia ; 580
Ferrari California T ; 530
Run Code Online (Sandbox Code Playgroud)
等等......我需要以两种方式对这个阵列进行排序:首先,按品牌(因此,宝马物品排在第一位)然后按价格排序,而不删除之前的效果.
问题是,如果我sort()按name属性排序,然后按price,首先排序效果将丢失.我该怎么办?
我有以下代码:
import re
r = re.compile('^[0-9 ]{1,4}Ty', 'i')
Run Code Online (Sandbox Code Playgroud)
我得到意外的错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.4/re.py", line 219, in compile
return _compile(pattern, flags)
File "/usr/lib/python3.4/re.py", line 275, in _compile
bypass_cache = flags & DEBUG
TypeError: unsupported operand type(s) for &: 'str' and 'int'
Run Code Online (Sandbox Code Playgroud)
怎么解决?
我刚刚在我的应用程序中遇到问题,我需要获取CreateWindowW函数的静态地址.像这样:
&ShowWindow;
Run Code Online (Sandbox Code Playgroud)
但是,当使用相同的技巧时CreateWindowW,我得到编译器错误 Identifier "CreateWindowW" is undefined(它是一个宏).我实际上找不到这个函数的定义(哪个DLL),甚至pinvoke.net也没有提到这个.
在某些网站上有提及它user32.dll,但GetProcAddress对于我的函数,它返回null指针.我迷路了,Windows上哪个模块链接了这个功能?
如果我尝试将调试器和跟踪调用连接到此函数,Visual Studio会"跳过"它,所以我无法理解调用的位置.
我的构建是UNICODE.WinUser.h文本我可以看到:
#define CreateWindowA(lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\
CreateWindowExA(0L, lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
#define CreateWindowW(lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\
CreateWindowExW(0L, lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
#ifdef UNICODE
#define CreateWindow CreateWindowW
#else
#define …Run Code Online (Sandbox Code Playgroud) 函数get1()和get2()的用法有什么不同?
struct x
{
float get1() const
{
float fx = 4;
fx += 1.5f;
return fx;
}
float& get2() const
{
float fx = 4;
fx += 1.5f;
return fx;
}
};
int main()
{
x t;
float x1 = t.get1();
float/*&*/ x2 = t.get2();
cout << x1 << endl;
cout << x2 << endl;
cin.get();
}
Run Code Online (Sandbox Code Playgroud)
据我所知,get2()只能是const类成员..我不完全清楚.如果有人可以指出我的参考或只是一个简短而完整的解决方案,那就太好了.
我的程序经常调用WINAPI函数timeGetTime(),应该替换为<chrono>(标准库)的使用.什么是最快的标准化的方式来获取系统时间-在float或int,我的情况?
我不需要跟踪日期或日期时间,我只需要精确的相对ms /秒值,它总是递增.有没有?
c++ ×4
python ×3
python-3.x ×2
winapi ×2
windows ×2
c++-chrono ×1
c++11 ×1
dllimport ×1
orm ×1
peewee ×1
reference ×1
regex ×1
return ×1
return-type ×1
return-value ×1
sockets ×1
sorting ×1
sqlite ×1
time ×1