typedef

How can I use templated typedefs, that are _in_ a class, from outside the class (e.g. by another class), in relation to boost::graph

Hi, I found a very useful answer on how to create templated graphs using boost::graph under http://stackoverflow.com/questions/671714/modifying-vertex-properties-in-a-boostgraph/950173#950173 For me, this is very convenient as long as I do all the work on the graph in the Graph-class itself. However, it might be necessary to access in...

C++ typedef interpretation of const pointers

Firstly, sample codes: Case 1: typedef char* CHARS; typedef CHARS const CPTR; // constant pointer to chars Textually replacing CHARS becomes: typedef char* const CPTR; // still a constant pointer to chars Case 2: typedef char* CHARS; typedef const CHARS CPTR; // constant pointer to chars Textually replacing CHARS becom...

"using typedef-name ... as class" on a forward declaration

I'm doing some policy-based designs here and I have the need to typedef lots of template types to shorten the names. Now the problem comes that when I need to use a pointer to one of those types I try to just forward-declare it but the compiler complains with a test.cpp:8: error: using typedef-name ‘Test1’ after ‘class’ It's nothing to ...

GCC: array type has incomplete element type ?!

GCC gives me an "array type has incomplete element type"-error message when i try to compile this: typedef struct _node node; struct _node{ int foo; node (*children)[2]; int bar; }; In memory the struct should look like this 0x345345000000 foo 0x345345000004 pointer to 1. child node 0x345345000008 pointer to 2. child node 0x345345...

Can somebody explain this C++ typedef ?

I've just started working with C++ after not having worked with it for quite a while. While most of it makes sense, there are some bits that I'm finding a bit confuddling. For example, could somebody please explain what this line does: typedef bool (OptionManager::* OptionHandler)(const ABString& value); ...

Typedeffing a function (NOT a function pointer)

typedef void int_void(int); int_void is a function taking an integer and returning nothing. My question is: can it be used "alone", without a pointer? That is, is it possible to use it as simply int_void and not int_void*? typedef void int_void(int); int_void test; This code compiles. But can test be somehow used or assigned to som...

Typedef compilation error on function overload

Why can't I compile the program 1 when the the program 2 is working fine ? Why is it's behavior different? Program 1: #include <iostream> typedef int s1; typedef int s2; void print(s1 a){ std::cout << "s1\n"; } void print(s2 a){ std::cout << "s2\n"; } int main() { s1 a; s2 b; print(a); print(b); ...

Header file best practices for typedefs

I'm using shared_ptr and STL extensively in a project, and this is leading to over-long, error-prone types like shared_ptr< vector< shared_ptr<const Foo> > > (I'm an ObjC programmer by preference, where long names are the norm, and still this is way too much.) It would be much clearer, I believe, to consistently call this FooListPtr and ...

Nesting aliases in C#

I've seen lots of answers to the typedef problem in C#, which I've used, so I have: using Foo = System.Collections.Generic.Queue<Bar>; and this works well. I can change the definition (esp. change Bar => Zoo etc) and everything that uses Foo changes. Great. Now I want this to work: using Foo = System.Collections.Generic.Queue<Bar>...

Objective-C. I have typedef float DuglaType[3]. How do I declare the property for this?

I have: typedef float DuglaType[3]; @interface Foo : NSObject { DuglaType _duglaType; } How do I correctly declare the property? I tried: // .h @property DuglaType duglaType; // .m @synthesize duglaType = _duglaType; But this spews errors. What is the secret handshake for C++ typedefs to play nice with Obj-C properties? Tha...

How to hide specific type completely using typedef?

I have a quick question about encapsulating specific types with typedef. Say I have a class Foo whose constructor takes a certain value, but I want to hide the specific type using typedef: class Foo { public: typedef boost::shared_ptr< std::vector<int> > value_type; Foo(value_type val) : val_(val) {} private: value_type val_; }...

Using typedefs from a template class in a template (non-member) function

The following fails to compile (with gcc 4.2.1 on Linux, anyway): template< typename T > class Foo { public: typedef int FooType; }; void ordinary() { Foo< int >::FooType bar = 0; } template< typename T > void templated() { Foo< T >::FooType bar = T( 0 ); } int main( int argc, char **argv ) { return 0; } The problem is ...

C++ visibility of privately inherited typedefs to nested classes

First time on StackOverflow, so please be tolerant. In the following example (apologies for the length) I have tried to isolate some unexpected behaviour I've encountered when using nested classes within a class that privately inherits from another. I've often seen statements to the effect that there is nothing special about a nested cl...

Can someone explain the difference between these two typedefs? (Function pointer related)

This one is quite obviously a function pointer : typedef int (* foobar) (int a, unsigned char *b, unsigned int c); But what does this one do? typedef int (foobar *) (int a, unsigned char *b, unsigned int c); ...

I want to extend std::string, but not for the reason you might think.

I have a method that effectively takes a string. However, there is a very limited subset of strings I want to use. I was thinking of typedef'ing std::string as some class, and call the functions explicit. I'm not sure that would work, however. Ideas? ...

Typedef and Struct in C and H files

I've been using the following code to create various struct, but only give people outside of the C file a pointer to it. (Yes, I know that they could potentially mess around with it, so it's not entirely like the private keyword in Java, but that's okay with me). Anyway, I've been using the following code, and I looked at it today, and...

Extracting pair member in lambda expressions and template typedef idiom

Hi, I have some complex types here so I decided to use nifty trick to have typedef on templated types. Then I have a class some_container that has a container as a member. Container is a vector of pairs composed of element and vector. I want to write std::find_if algorithm with lambda expression to find element that have certain value. T...

What can I do with an enum variable?

When I declare a enum variable like this: enum paint_colors { RED, GREEN, BLUE, ...} colors; is the colors variable useful? If so, what can I do with it? Thanks in advance. ...

C++ -- typedef "inside" template arguments?

Imagine I have a template function like this: template<typename Iterator> void myfunc(Iterator a, typename Iterator::value_type b) { ... } Is there a way to implement the same thing by declare a typedef for Iterator::valuetype that I can use in the function signature? For example, I'd prefer to be able to do something like this: tem...

What is the use of typedef?

What is the use of typedef keyword in C ? When is it needed? ...