1

I found the following code (auto-generated, but it does not compile) and now I whant to know what it means:

template<> struct topic_type_support<UnboundedStringWithKey> 
{            
    typedef UnboundedStringWithKey##TypeSupport type;                
};

As some persons pointed out ## is meant for macros and indeed the code was inside a macro. I wasn't aware of this and tried to put it directly into the code to get a clearer error message. The original macro was:

#define REGISTER_TOPIC_TRAITS(TOPIC)                    \
namespace dds { namespace topic {                    \
template<> struct topic_type_support<TOPIC> {            \
    typedef TOPIC##TypeSupport type;                \
};                                \
template<> struct is_topic_type<TOPIC> { enum {value = 1 }; };    \
template<> struct topic_type_name<TOPIC> {            \
    static std::string value() {                    \
        static topic_type_support<TOPIC>::type ts;            \
        return ts.get_type_name();                    \
    }                                \
};                                \
} }  

The original compiler error is: syntax error : missing ';' before identifier 'type'

I manually inserted the macro and applied ##:

template<> struct topic_type_support<UnboundedStringWithKey> 
{            
    typedef UnboundedStringWithKeyTypeSupport type;                
}; 

but it says directly in the line with the typedef: missing ';' before identifier 'type' (compiler is VS2010 with SP1 installed)

can anybody tell me? (the code is generated by idlpp.exe from OpenSplice)

the reason is now clear (I forgot the #pragma keylist entry in the idl) - there is no UnboundedStringWithKeyTypeSupport generated. But that's a different question.

Regards Tobias

Reinier Torenbeek
  • 16,669
  • 7
  • 46
  • 69
Tobias Langner
  • 10,634
  • 6
  • 46
  • 76
  • 2
    It is the explicit specialization of a class template. The `typedef` was probably meant to be generated by a macro, but something went wrong when concatenating two tokens – Andy Prowl Jun 20 '13 at 17:32
  • Looks like something using the `##` operator for macros. Perhaps it's supposed to be in a macro? – Mats Petersson Jun 20 '13 at 17:33
  • 1
    Right, so the C prerprocessor SHOULD expand that by pasting whatever is in `TOPIC` together with `TypeSupport` - for example, if we use REGISTER_TOPIC_TRAITS(foo)`, it would make a `template<> topic_type_support typedef fooTypeSupport type;`. I don't see any reason why this wouldn't compile – Mats Petersson Jun 20 '13 at 17:46
  • 1
    Looks like you don't have a type named `UnboundedStringWithKeyTypeSupport`. – Casey Jun 20 '13 at 18:05
  • Thank you for your help. If someone posts the macro concatenation as answer, I'll upvote and accept. – Tobias Langner Jun 20 '13 at 18:06

0 Answers0