Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to interpret a typedef <>

Posted on 2013-06-25
2
Medium Priority
?
295 Views
Last Modified: 2013-06-28
I have structure

struct ace {
     uint32_t type;
     uint32_t flag;
}

typedef ace  ace_attr<>

What does <>  mean? Can someone please illustrate with an example
0
Comment
Question by:perlperl
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 39275074
This defines 'ace' as type for the template specialization 'ace_attr<>' of the template class 'ace_attr<typename T>' - you should find a declaration like

template<typename T> 
class ace_attr {

  // ...
};

Open in new window


somehere in your code as well. See also http://en.wikipedia.org/wiki/Template_(C%2B%2B)#Explicit_template_specialization and http://www.cprogramming.com/tutorial/template_specialization.html
0
 
LVL 40

Expert Comment

by:evilrix
ID: 39275638
>> This defines 'ace' as type for the template specialization...
Indeed, that is the most logical conclusion; however, for that to be the case the parameters need to be swapped.

eg.

typedef ace_attr<> ace;  

perlperl, did you copy/paste that example or type it in? If the latter, is it possible you've transposed the parameters? If so then jkr is spot on and you should accept his answer. If not it would help if you could actually copy and past the code and the context in which it's used.

Additional (please don't award this any points it just buils on what jkr has already said):

The ace_attr<> is just referencing a template type that has a default value defined. In your code you'll have something like...

template<typename T = <sometype>>
class ace_attr { };

Note, this is what jkr suggested and all I've done is add the default parameter. This allows you to instantiate the template without a type because the default will be used. This is not too dis-similar to default arguments for function parameters.

void foo(int n = 1) {}

This can be called as such...

foo();

It's basically the same thing but with templates rather than function calls.

Cheers.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question