问题:
class Base {
public:
Base(Base* pParent);
/* implements basic stuff */
};
class A : virtual public Base {
public:
A(A* pParent) : Base(pParent) {}
/* ... */
};
class B : virtual public Base {
public:
B(B* pParent) : Base(pParent) {}
/* ... */
};
class C : public A, public B {
public:
C(C* pParent) : A(pParent), B(pParent) {} // - Compilation error here
/* ... */
};
Run Code Online (Sandbox Code Playgroud)
在给定的位置,gcc抱怨它无法匹配函数调用Base(),即默认构造函数.但是C不直接从Base继承,只通过A和B.那么为什么gcc会在这里抱怨?
想法?TIA/Rob
我想在编译时根据派生类型为类生成哈希.今天我生成它像:
template<class Type>
class TypeBase
{
public:
static const unsigned s_kID;
};
template<class Type>
const unsigned TypeBase<Type>::s_kID = hash(typeid(Type));
Run Code Online (Sandbox Code Playgroud)
但这会产生(非常不必要)运行时初始化代码(hash(..)函数根据std :: type_info :: name()执行简单的哈希)
想法?
我正在寻找一种方法来映射类型,fi有一个类Double:
class Double
{
public:
typedef double basic_type;
...
};
Run Code Online (Sandbox Code Playgroud)
我希望能够有一个类型的连铸机
typeid(TypeToObjectType<double>::type) == typeid(Double)
Run Code Online (Sandbox Code Playgroud)
任何想法如何实现这一点(通过部分专业化等)?
我打算做一个C++插件接口ala 如何从dll创建一些类(dll中的构造函数)?(с++) 但是有人担心如果接口用于通过MinGW或Borland和DLL创建DLL loader是用MSVC++编译的,可能有问题.由于唯一导出的函数被声明为extern"C",我不明白为什么它不起作用?
想法?
我想在Ubuntu机器上设置几个环境变量(10.04),但我想通过脚本创建它们的值,就像:
export THE_ENV_VAR=$(script_to_execute_and_use_stdout_from)
Run Code Online (Sandbox Code Playgroud)
我尝试过设置/etc/environment,但只能逐字复制rhs
我已经尝试/etc/init.d/在启动时执行脚本,但这似乎不起作用.
想法?
我正在尝试设置一个通用的 .gitmodules 文件,用作新项目始终需要的特定静态数量的子模块的模板。然后使用从 .gitmodules 恢复 git submodules 中显示的技术一次性初始化子模块:
#!/bin/sh
#set -e
git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
while read path_key path
do
url_key=$(echo $path_key | sed 's/\.path/.url/')
url=$(git config -f .gitmodules --get "$url_key")
branch_key=$(echo $path_key | sed 's/\.path/.branch/')
branch=$(git config -f .gitmodules --get "$branch_key")
if [ ! -d "$path" ]; then
echo URL - $url, Path - $path, Branch - $branch
if [ -n "$branch" ]; then
branch="-b $branch"
fi
git submodule add --force $branch …Run Code Online (Sandbox Code Playgroud) 我有一个函数声明为:
int myFunction(const float** ppArr, const int n, const int m);
Run Code Online (Sandbox Code Playgroud)
当我这样称呼时:
float** ppArr = new float*[5];
// Some initialization of ppArr
int result = myFunction(ppArr, 5, 128); <<<< Error
Run Code Online (Sandbox Code Playgroud)
而错误是(VS 2008 Express):
error C2664: 'Test_myFunction.cpp' : cannot convert parameter 1 from 'float **' to 'const float **'
Run Code Online (Sandbox Code Playgroud)
WTF?我正在将一个浮动**转换为const float**.可能出现什么问题?:/
编辑:谢谢你非常快速的回复!:)
我现在有一个工作实现,映射范围的键,如下所示:
class Range {
public:
Range(int from, int to = -1) : _from(from), _to( to >= 0 ? to : from) {}
bool operator < (const Range& item) {
return _to < item._from;
}
bool operator == (const Range& item) {
return item._from >= _from && item._to <= _to;
}
private:
int _from, _to;
};
typedef std::map<Range, MappedType> my_map_type;
Run Code Online (Sandbox Code Playgroud)
很酷的是,我能做到:
my_map_type m;
m[Range(0, 20)] = Item1;
m[Range(30,40)] = Item2;
my_map_type::iterator it = m.find(15);
assert(it->second == Item1);
it = m.find(40);
assert(it->second …Run Code Online (Sandbox Code Playgroud)