Solved

How to interpret a typedef <>

Posted on 2013-06-25
2
290 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
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

777 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