?
Solved

How to interpret a typedef <>

Posted on 2013-06-25
2
Medium Priority
?
294 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 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

770 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