小编Rya*_*yan的帖子

GCC错误:非命名空间范围的显式特化

我试图移植以下代码.我知道标准不允许在非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)

c++ gcc templates

27
推荐指数
2
解决办法
2万
查看次数

模板继承内部类访问问题

我不敢相信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)

c++ inheritance templates class

9
推荐指数
2
解决办法
2078
查看次数

...在联合问题中不允许使用构造函数

我迫切需要找到解决以下问题的方法:

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)

c++ gcc struct visual-c++ unions

8
推荐指数
2
解决办法
1万
查看次数

奇怪的GCC错误:在','标记之前预期的主要表达式

我仍然在试图从迁移到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)

请帮忙!

c++ gcc templates

7
推荐指数
1
解决办法
5793
查看次数

GCC内联汇编错误:无法获取'this'的地址,这是一个rvalue表达式

我还在和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实例的指针?

c++ assembly xcode gcc inline-assembly

6
推荐指数
1
解决办法
727
查看次数

如何实现MS特定的_BitScanReverse()函数?

来自 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()函数?我必须使用汇编还是有更简单的方法?

c++ gcc bit visual-c++

5
推荐指数
1
解决办法
7122
查看次数

如何定义自定义Mac OS X框架/动态库的可选入口点?

在Windows中有一个DllMainDLL_PROCESS_ATTACH/DLL_PROCESS_DETACH标志,允许在DLL附加到进程后初始化/释放资源...那么如何在OS X的情况下指定入口点?一如既往,我在Apple文档中找不到任何有用的东西:(

c++ macos dll frameworks entry-point

5
推荐指数
2
解决办法
2717
查看次数

Apple GCC 4.2.1将指针传递给构造函数

假设我有一个类,并且它或它的成员没有明显的问题,但是如果我尝试将几个类成员的地址传递给同一模块中的另一个类,则第一个参数正确传递,但第二个参数正确传递永远是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)

c++ alignment

5
推荐指数
1
解决办法
186
查看次数

为什么简单的内联汇编功能在GCC中不能正常工作?

我有一个简单的内联汇编函数,它在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)

c++ xcode gcc inline-assembly

4
推荐指数
1
解决办法
3777
查看次数

如何在 Cocoa 应用程序中关闭键盘声音?

我的OpenGL Cocoa应用程序有问题- 每次触发keyUp / KeyDown事件时,都会播放系统声音...如何为我的应用程序禁用此逻辑?

我有一种不好的感觉,由于某种奇怪的原因,我的应用程序可能会将按键视为错误并播放系统警报声音......请帮忙!

c++ cocoa objective-c

4
推荐指数
1
解决办法
2280
查看次数