Search code examples
c++template-specializationrhapsody

Explicit member specialization using IBM Rational Rhapsody


I want to explicitly specialize some member functions inside a class using IBM Rational Rhapsody.

What I have done so far; I created a function inside a regular class, marked it as a template. Marked CG::Generate to Specification. This will be the prototype of the template.

Then I created another function. Marked it as a template. Pointed the function I created above as Primary Template under Template Parameters. Filled Implementation. Here is the code that Rhapsody generates:

//## class MyConvert
class MyConvert {
////    Constructors and destructors    ////

public :

MyConvert();

~MyConvert();

////    Operations    ////

//## operation strtox(char*,char*)
template <typename T> inline static T strtox(char* in, char** end);

//## operation strtox(char*,char**)
template <> inline double strtox<double>(char* in, char** end) {
    //#[ operation strtox(char*,char**)
    return strtod(in, end);           
    //#]
}
};

When I compile this, I get this: error: explicit specialization in non-namespace scope 'class MyConvert'

Explicit specialization should be implemented outside of class definition, like this:

//## class MyConvert
class MyConvert {
    ////    Constructors and destructors    ////

public :

    MyConvert();

    ~MyConvert();

    ////    Operations    ////

    //## operation strtox(char*,char*)
    template <typename T> inline static T strtox(char* in, char** end);
};

//## operation strtox(char*,char**)
template <> inline double MyConvert::strtox<double>(char* in, char** end) {
    //#[ operation strtox(char*,char**)
    return strtod(in, end);           
    //#]
}

How to achieve this using Rhapsody?


Solution

  • It's not precisely the answer but a workaround to have specialized functions. Surely, it does the trick.

    Instead of defining the functions inside the class, define them inside the package. This way, implementation will be outside of the class scope. Class member functions can still access functions defined within the package.

    I posted detailed explanation to my blog. If interested: http://kaskavalci.com/?p=323