typedef

Forward-declare enum in Objective-C

I'm having trouble with enum visibility in an Objective-C program. I have two header files, and one defines a typedef enum. Another file needs to use the typedef'd type. In straight C, I would simply #include the other header file, but in Objective-C, it's recommended not to use #import between header files, instead using forward @class...

What is the purpose of typedefing a class in C++?

I've seen code like the following frequently in some C++ code I'm looking at: typedef class SomeClass SomeClass; I'm stumped as to what this actually achieves. It seems like this wouldn't change anything. What do typedefs like this do? And if this does something useful, is it worth the extra effort? ...

A function pointer that points to a function that takes an object of a template class with said function pointer as template argument. Possible?

x__x I want to do something like this: typedef long (* fp)(BaseWindow< fp > & wnd, HWND hwnd, long wparam, long lparam); But I get a compile error: error C2065: 'fp' : undeclared identifier Is it possible to implement this somehow? ...

Convert objective-c typedef to its string equivalent

Assuming that I have a typedef declared in my .h file as such: typedef enum { JSON, XML, Atom, RSS } FormatType; I would like to build a function that converts the numeric value of the typedef to a string. For example, if the message [self toString:JSON] was sent; it would return 'JSON'. The function would look something lik...

Do typedefs of templates preserve static initialization order?

Within the same compilation unit, the C++ standard says that static initialization order is well defined -- it's the order of the declarations of the static objects. But using the Sun Studio 12 compiler I'm encountering unintuitive behavior. I've define a templated class helper<T> which contains a static member _data of type T and a stat...

C Typedef and Struct Question

What's the difference between these two declarations, and is one preferred over the other? typedef struct IOPORT { GPIO_TypeDef* port; u16 pin; } IOPORT; typedef struct { GPIO_TypeDef* port; u16 pin; } IOPORT; ...

What is the difference when using typdef when declaring a stuct c++?

Possible Duplicates: Why should we typedef a struct so often in C? Difference between struct and typedef struct in C++? What is the difference between the following type declarations? struct Person { int age; }; typedef struct { int age; }Person; I understand that struct { int age; }Person; Creates and ...

Naming scheme for typedefs

I'm working on a library that extensively used constructs like typedef struct foo_bar_s { ... } foo_bar_t; It's a bad idea to use the _t suffix, because it's a POSIX reserved namespace. The _s suffix for structs is also pretty useless. So I thought I can change it all to typedef struct foo_bar { ... } foo_bar; or if the str...

Is there a Java equivalent or methodology for the typedef keyword in C++?

Coming from a C and C++ background, I found judicious use of typedef to be incredibly helpful. Do you know of a way to achieve similar functionality in Java, whether that be a Java mechanism, pattern, or some other effective way you have used? Thanks, -bn ...

Why is the use of typedef in this template necessary?

When I compile this code in Visual Studio 2005: template <class T> class CFooVector : public std::vector<CFoo<T>> { public: void SetToFirst( typename std::vector<CFoo<T>>::iterator & iter ); }; template <class T> void CFooVector<T>::SetToFirst( typename std::vector<CFoo<T>>::iterator & iter ) { iter = begin(); ...

C++ STL map typedef errors

I'm having a really nasty problem with some code that I've written. I found someone else that had the same problem on stackoverflow and I tried the solutions but none worked for me. I typedef several common STL types that I'm using and none of the others have any problem except when I try to typedef a map. I get a "some_file.h:83: erro...

How do i forward declare a class that has been typedef'd?

I have a string class that, unsurprisingly, uses a different implementation depending on whether or not UNICODE is enabled. #ifdef UNICODE typedef StringUTF16 StringT; #else typedef StringUTF8 StringT; #endif This works nicely but I currently have a problem where I need to forward declare the StringT typedef. How can I do this? I ca...

Is there ever justification for the "pseudo-typedef antipattern"?

I have a relatively complicated generic type (say Map<Long,Map<Integer,String>>) which I use internally in a class. (There is no external visibility; it's just an implementation detail.) I would like to hide this in a typedef, but Java has no such facility. Yesterday I rediscovered the following idiom and was disappointed to learn that ...

C++ Class forward declaration drawbacks?

Hi! I want to use forward declaration of a class in my software, so I can have typedefs and use them inside the class full declaration. Smth like this: class myclass; typedef boost::shared_ptr<myclass> pmyclass; typedef std::list<pmyclass > myclasslist; class myclass : public baseclass { private: // private member declaration...

Template's member typedef use in parameter undeclared identifier in VS but not GCC

I'm looking at some codes which makes heavy uses of templates. It compiles fine on GCC, but not on VS (tested on 2003 - 2010 beta 1), where it fails during syntax analysis. Unfortunately I don't know enough of the code structure to be able reduce the problem and reproduce it in only a few lines, so I can only guess at the cause. I'm hopi...

Doxygen and typedefs

Could someone tell me what is wrong with this code so doxygen cannot handle? /*! \file Enumerator.h \brief Implements an Enumerator pointer for accessing linked list elements. */ #pragma once #ifndef __MSCL_ENUMERATOR_H__ #define __MSCL_ENUMERATOR_H__ namespace MSCL { /*! \typedef Enumerator Pointer to linked list data structu...

C++: Callback typedefs with __stdcall in MSVC

This typedef: typedef DWORD WINAPI (* CM_Open_DevNode_Key)(DWORD, DWORD, DWORD, DWORD, PHKEY, DWORD); compiles fine in BorlandCpp, however, when I compile it in msvc I have to remove WINAPI (which is just an alias for __stdcall): typedef DWORD (* CM_Open_DevNode_Key)(DWORD, DWORD, DWORD, DWORD, PHKEY, DWORD); Why is this happening?...

Is there a way to typedef this?

Simplified version of the code: Foo.h: class Foo { private: class Bar { // ... }; typedef std::map<int, Bar> mapType; mapType _map; public: void method(mapType::iterator it); }; Foo.cpp: void Foo::method(mapType::iterator it) { // ... notMethod(it); } void notMetho...

Is it legal C++ to use a typedef in a method declaration but the canonical type in the method definition?

The GNU C++ (g++ -pedantic -Wall) accepts this: typedef int MyInt; class Test { public: MyInt foo(); void bar(MyInt baz); }; int Test::foo() { return 10; } void Test::bar(int baz) { } int main(void) { Test t; t.bar(t.foo()); return 0; } Is it legal C++? Are other compilers likely to accept it? ...

private typedef visible in derived class

Hi everyone, I have a small problem with my compiler (VC++ 6.0). In my opinion, such a code should cause error; class Base { private: typedef int T; }; class Derived : private Base // Here the Base class can be inherited publicly as well. It does not play any role { public: T z; }; int main() { Derived o...