Solved

How to interpret a typedef <>

Posted on 2013-06-25
2
287 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 500 total points
Comment Utility
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
Comment Utility
>> 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 Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now