Solved

How to interpret a typedef <>

Posted on 2013-06-25
2
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ error cannot convert from std::string to const char * 6 312
Acrinis True image 2 111
Which Linux flavors will this run on? 6 102
delete-remove 14 108
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 and use switch statements in the C programming language.

730 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