[aspectc-user] Problem with static member variable in template class

Jens Schedel jens at schedel.org
Tue Jun 8 13:11:14 CEST 2010


Hi,

i have an problem with the following piece of code:

================================================================================
#include <stdlib.h>
#include <stdint.h>

template<typename _OPMODE_T, uint16_t _GROUP> class Test {
    private:
        static _OPMODE_T opMode;

    public:
        void setOpMode(_OPMODE_T newMode);
};

template<typename _OPMODE_T, uint16_t _GROUP> void Test<_OPMODE_T, _GROUP>::setOpMode(_OPMODE_T newMode) {
// Error: error: invalid statement near token `='
    Test<_OPMODE_T, _GROUP>::opMode = newMode;

// Works
//  opMode = newMode;
}

template<typename _OPMODE_T, uint16_t _GROUP> _OPMODE_T Test<_OPMODE_T, _GROUP>::opMode = _OPMODE_T();

================================================================================


Compiling the code with: ag++ --real-instances results in the following error message:
error: invalid statement near token `='

As you see in the code, if i remove the type in front of opMode then ag++ stops complaining.
g++ has no problem with both variants.


I just wanted to reduce the code and removed the second template parameter and
figured out that the following pieces of code also compile without errors:

================================================================================
#include <stdlib.h>
#include <stdint.h>

template<typename _OPMODE_T> class Test {
    private:  
        static _OPMODE_T opMode;

    public:
        void setOpMode(_OPMODE_T newMode);
};

template<typename _OPMODE_T> void Test<_OPMODE_T>::setOpMode(_OPMODE_T newMode) {
    Test<_OPMODE_T>::opMode = newMode;
}

template<typename _OPMODE_T> _OPMODE_T Test<_OPMODE_T>::opMode = _OPMODE_T();

================================================================================
#include <stdlib.h>
#include <stdint.h>

template<uint16_t _GROUP> class Test {
    private:
        static uint16_t opMode;

    public:
        void setOpMode(uint16_t newMode);
};

template<uint16_t _GROUP> void Test<_GROUP>::setOpMode(uint16_t newMode) {
    Test<_GROUP>::opMode = newMode;
}

template<uint16_t _GROUP> uint16_t Test<_GROUP>::opMode;

================================================================================


Regards,
Jens
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3230 bytes
Desc: not available
URL: <http://www.aspectc.org/pipermail/aspectc-user/attachments/20100608/f1672731/attachment.bin>


More information about the aspectc-user mailing list