我有一个项目,我希望更好地使用智能指针.
主要思想是从函数返回新对象时使用它们.问题是使用什么智能指针?来自boost的auto_ptr或shared_ptr?据我所知,auto_ptr较慢,但它可以回退到'纯'指针.
如果我在不需要它的地方使用智能指针,它会使性能变慢吗?
我XML在我的应用程序中使用了一些自己的XML解析器(来自ClanLib库).
问题是:解析器无法验证XML,如果出现任何错误,它将失败.我需要一些验证器,它会说是否XML有效并且(最好)显示错误.
我需要在文件中将一些字符串替换为另一个字符串 我知道如何使用单个文件:sed -i 's/a/b/'.但是递归函数怎么样?我想我必须以find . -name *某种方式使用xargs.
我需要你的帮助 :)
class Object { };
Class Derived : public Object { };
boost::shared_ptr<Object> mObject(new Derived); // Ok
Run Code Online (Sandbox Code Playgroud)
但是如何把它投到boost::shared_ptr<Derived>?
我尝试了类似的东西:static_cast< boost::shared_ptr<Derived> >(mObject)它失败了.
唯一的工作理念是:
boost::shared_ptr<Derived> res(new dynamic_cast<Derived*>(mObject.get()))
我正在QtCreator的设计师中编写C++/Qt界面.用一些背景图像选择制作哪个元素作为矩形?
第二个问题:如何绘制平铺图像?我有和大小(1×50)的图像,我想渲染它的父宽度.有任何想法吗?
mTopMenuBg = QPixmap("images/top_menu_bg.png");
mTopMenuBrush = QBrush(mTopMenuBg);
mTopMenuBrush.setStyle(Qt::TexturePattern);
mTopMenuBrush.setTexture(mTopMenuBg);
ui->graphicsView->setBackgroundBrush(mTopMenuBrush);
Run Code Online (Sandbox Code Playgroud)
QBrush:TexturePattern的使用不正确
我有一个无法在堆上创建的类,它有私有析构函数.
但是有一个函数返回指向这种构造对象的指针.我想从它做一个共享指针:
MyClass *GetMyClassPointer() {...}
boost::shared_ptr<MyClass> ptr;
ptr = boost::shared_ptr<MyClass>(GetMyClassPointer()); // [x]
Run Code Online (Sandbox Code Playgroud)
错误:'MyClass :: ~MyClass()'是私有的
无论如何?
我想为我的游戏制作一些存储空间.现在代码看起来像:
class WorldSettings
{
private:
std::map<std::string, int> mIntegerStorage;
std::map<std::string, float> mFloatStorage;
std::map<std::string, std::string> mStringStorage;
public:
template <typename T>
T Get(const std::string &key) const
{
// [?]
}
};
Run Code Online (Sandbox Code Playgroud)
所以,我有一些关联容器存储确切的数据类型.现在我想在设置中添加一些值:settings.Push<int>("WorldSize", 1000);并得到它:settings.Get<int>("WorldSize");.但是由于传递类型到模板中如何切换需要地图?
或者,也许,你知道更好的方式,谢谢.
我已经下载了一些旧项目的源代码。我现在正在尝试构建它:
./bootstrap && ./configure
Run Code Online (Sandbox Code Playgroud)
它工作正常,但是:
make
/bin/sh ../libtool --mode=compile g++ -DHAVE_CONFIG_H -I. -I.. -W -g -O2 -DDEBUG -MT rcclexer.lo -MD -MP -MF .deps/rcclexer.Tpo -c -o rcclexer.lo rcclexer.cpp
../libtool: line 415: CDPATH: command not found
libtool: Version mismatch error. This is libtool 2.4.2, but the
libtool: definition of this LT_INIT comes from an older release.
libtool: You should recreate aclocal.m4 with macros from libtool 2.4.2
libtool: and run autoconf again.
Run Code Online (Sandbox Code Playgroud)
ps那个小项目页面:http : //sourceforge.net/projects/rccparser/
有什么帮助吗?
我必须获取字节数组并将其发送到套接字.
结构如下:1字节+ 2字节+ 2字节.
第一个字节是数字'5',第二个字节应该从变量中获取first,第三个字节应该从变量中获取second.在python中执行此操作的正确方法是什么?
id = 5 # Fill as 1 byte
first = 42 # Fill as 2 bytes
second = 58 # The same as first
Run Code Online (Sandbox Code Playgroud) 我用python解析html,并且有日期字符串:[ 24-???-17 07:24 ]。“ ???” 是“ Jan”。我想将其转换为datetime对象。
# Some beautifulsoup parsing
timeData = data.find('div', {'id' : 'time'}).text
import locale
locale.setlocale(locale.LC_TIME, 'ru_RU.UTF-8')
result = datetime.datetime.strptime(timeData, u'[ %d-%b-%y %H:%M ]')
Run Code Online (Sandbox Code Playgroud)
错误是:
ValueError:时间数据'[24- \ xd0 \ xaf \ xd0 \ xbd \ xd0 \ xb2-17 07:24]'与格式'[%d-%b-%y%H:%M]'不匹配
type(timeData)返回unicode。timeData从utf-8返回编码UnicodeEncodeError。怎么了?
chardet返回{'confidence': 0.87625, 'encoding': 'utf-8'},当我写的时候:datetime.datetime.strptime(timeData.encode('utf-8'), ...)返回上面的错误。
原始页面具有window-1251编码。
print type(timeData)
print timeData
timeData = timeData.encode('cp1251')
print type(timeData)
print timeData
Run Code Online (Sandbox Code Playgroud)
退货
<type 'unicode'>
[ …Run Code Online (Sandbox Code Playgroud)