我试图移植以下代码.我知道标准不允许在非namescape范围内进行显式特化,我应该使用重载,但我找不到在这种特殊情况下应用这种技术的方法.
class VarData
{
public:
template < typename T > bool IsTypeOf (int index) const
{
return IsTypeOf_f<T>::IsTypeOf(this, index); // no error...
}
template <> bool IsTypeOf < int > (int index) const // error: explicit specialization in non-namespace scope 'class StateData'
{
return false;
}
template <> bool IsTypeOf < double > (int index) const // error: explicit specialization in non-namespace scope 'class StateData'
{
return false;
}
};
Run Code Online (Sandbox Code Playgroud) 我不敢相信gcc不会接受以下代码...请告诉我,如果从基本模板访问内部类是真的不可能或我错过了什么?
template <class T> class BaseClass
{
public:
struct MyStruct
{
T *data;
};
};
template <class T> class ChildClass : public BaseClass <T>
{
public:
void problem()
{
MyStruct ms1; //error: 'MyStruct' was not declared in this scope
::MyStruct ms2; //error: '::MyStruct' has not been declared
BaseClass<T>::MyStruct ms3; //error: expected `;' before 'ms3'
}
};
Run Code Online (Sandbox Code Playgroud) 我迫切需要找到解决以下问题的方法:
namespace test
{
template <int param = 0> struct Flags
{
int _flags;
Flags()
{
_flags = 0;
}
Flags(int flags)
{
_flags = flags;
}
void init()
{
}
};
union example
{
struct
{
union
{
struct
{
Flags<4096> f;
}p1; //error: member 'test::example::<anonymous struct>::<anonymous union>::<anonymous struct> test::example::<anonymous struct>::<anonymous union>::p1' with constructor not allowed in union
struct
{
Flags<16384> ff;
}p2; //error: member 'test::example::<anonymous struct>::<anonymous union>::<anonymous struct> test::example::<anonymous struct>::<anonymous union>::p2' with constructor not allowed in union
}parts; …Run Code Online (Sandbox Code Playgroud) 我仍然在试图从迁移到MSVC GCC,但我似乎无法找到解决如下问题:
template < typename A, typename B, typename C, typename D >
class Test
{
public:
Test (B* pObj, C fn, const D& args) : _pObj(pObj), _fn(fn), _args(args)
{
}
A operator() ()
{
return _args.operator() < A, B, C > (_pObj, _fn); // error: expected primary-expression before ',' token
}
B* _pObj;
C _fn;
D _args;
};
Run Code Online (Sandbox Code Playgroud)
请帮忙!
我还在和GCC打架- 编译下面的内联汇编代码(带-fasm-blocks,它启用了英特尔风格的汇编语法)给我一个奇怪的错误不能取'this'的地址,这是一个rvalue表达式 ...
MyClass::MyFunction()
{
_asm
{
//...
mov ebx, this // error: Cannot take the address of 'this', which is an rvalue expression
//...
mov eax, this // error: Cannot take the address of 'this', which is an rvalue expression
//...
};
}
Run Code Online (Sandbox Code Playgroud)
为什么我可以将指针存储到寄存器中的不同对象,但是不能使用指向MyClass实例的指针?
来自 MSDN 从最高有效位 (MSB) 到最低有效位 (LSB) 搜索掩码数据以查找设置位 (1)。
unsigned char _BitScanReverse ( unsigned long * Index, unsigned long Mask );
参数 [out] Index 加载找到的第一个设置位 (1) 的位位置。
[in] Mask 要搜索的 32 位或 64 位值。
如果掩码为零,则返回值0;否则非零。
备注 如果找到设置位,则在第一个参数中返回找到的第一个设置位的位位置。如果没有找到设置位,则返回0;否则返回1。
请告诉我如何在OS X上实现安全快速的_BitScanReverse()函数?我必须使用汇编还是有更简单的方法?
在Windows中有一个DllMain和DLL_PROCESS_ATTACH/DLL_PROCESS_DETACH标志,允许在DLL附加到进程后初始化/释放资源...那么如何在OS X的情况下指定入口点?一如既往,我在Apple文档中找不到任何有用的东西:(
假设我有一个类,并且它或它的成员没有明显的问题,但是如果我尝试将几个类成员的地址传递给同一模块中的另一个类,则第一个参数正确传递,但第二个参数正确传递永远是NULL!怎么会这样?是否会出现某种隐藏的堆栈/堆损坏或某种对齐问题?MSVC没有问题,但......
class myType2
{
char c1;
char c2;
} __attribute__ ((aligned (1))); // Yes, align differs and I can't change it
class MyClass2
{
public:
MyClass2(myType1* type1, myType2* type2, int data)
{
// type1 and data are ok, but type2 is NULL...
}
} __attribute__ ((aligned (16)));
class MyClass
{
public:
myType1 type1;
myType2 type2;
//....
void test()
{
MyClass2 test1(&this->type1, &this->type2, 170);
MyClass2* pTest2 = new MyClass2(&this->type1, &this->type2, 170); // Same result
myType2 localType2;
MyClass2 …Run Code Online (Sandbox Code Playgroud) 我有一个简单的内联汇编函数,它在MSVC中工作正常,但由于某种原因拒绝在Apple GCC 4.2.1(i386 arch,强制32位模式)下工作.幸运的是,更复杂的汇编函数工作得很好,但是我无法理解为什么这个函数不能正常工作...不幸的是,我无法调试它 - 看看事情在XCode 4.0.2中没有寄存器窗口(它是3.2版本).
我很肯定这个问题与英特尔风格的装配无关.
int Convert(double value)
{
_asm
{
fld value
push eax
fistp dword ptr [esp]
pop eax
}
// The returned value is insane
}
Run Code Online (Sandbox Code Playgroud) 我的OpenGL Cocoa应用程序有问题- 每次触发keyUp / KeyDown事件时,都会播放系统声音...如何为我的应用程序禁用此逻辑?
我有一种不好的感觉,由于某种奇怪的原因,我的应用程序可能会将按键视为错误并播放系统警报声音......请帮忙!
c++ ×10
gcc ×6
templates ×3
visual-c++ ×2
xcode ×2
alignment ×1
assembly ×1
bit ×1
class ×1
cocoa ×1
dll ×1
entry-point ×1
frameworks ×1
inheritance ×1
macos ×1
objective-c ×1
struct ×1
unions ×1