typedef

Better way to forward declare typedef'd structures in C89?

struct SomeStruct; typedef struct SomeStruct SomeStruct; The above works, but is there a simpler (or better) way? ...

Why do I need to use typedef typename in g++ but not VS?

It had been a while since GCC caught me with this one, but it just happened today. But I've never understood why GCC requires typedef typename within templates, while VS and I guess ICC don't. Is the typedef typename thing a "bug" or an overstrict standard, or something that is left up to the compiler writers? For those who don't know w...

templated typedef ?

I'm using libgc, a garbage collector for C and C++. To make STL containers garbage collectible one must use the gc_allocator. Instead of writing std::vector<MyType> one has to write std::vector<MyType,gc_allocator<MyType> > Could there be a way to define something like template<class T> typedef std::vector<T,gc_allocator<T> ...

invalid use of incomplete type

I'm trying to use a typedef from a subclass in my project, I've isolated my problem in the example below. Does anyone know where I'm going wrong? template<typename Subclass> class A { public: //Why doesn't it like this? void action(typename Subclass::mytype var) { (static_cast<Subclass*>(this))->do_action(var); ...

Mixed indexing behaviour for typedef array?

I have a typedef: typedef unsigned char MyType[2]; I pass it to a function and the result is FAIL! void f(MyType * m) { *m[0] = 0x55; *m[1] = 0x66; } void main(void) { Mytype a; a[0] = 0x45; a[1] = 0x89; f(&a); } The manipulation of variable a in main() works on 1 byte indexing, so a is equal to {0x45, 0x89}. However in function...

Smart typedefs

I've always used typedef in embedded programming to avoid common mistakes: int8_t - 8 bit signed integer int16_t - 16 bit signed integer int32_t - 32 bit signed integer uint8_t - 8 bit unsigned integer uint16_t - 16 bit unsigned integer uint32_t - 32 bit unsigned integer The recent embedded muse (issue 177, not on the website yet) intr...

C : function pointer and typedef problem

I have a C function that takes a function pointer as argument, it's a destructor that I'll call at the end of my program. Here is the prototype of my function : int store_dest(void (*routine)(void *)); I want to store this function pointer into a structure with some other infos. In order to have a nice struct, I want to have a typedef...

How to create keywords/types in C#?

Duplicate typedef in C#? Is there a way to create actually keywords in C#. Like for example turning object x into a datatype like int? I guess I'm asking is there anything like a typedef for C# and if not how can I actually make my own types that look like this: public static crap Main(string[] args) { // Note 'crap' and not...

C++ syntax question

Hi, What does the following syntax mean? typedef void* hMyClass; //typedef as a handle or reference hMyClass f = &something; const MyClass& foo = static_cast<MyClass&>(*f); foo.bar(); ...

TypeDef as an overridable class feature

Ok folks, if I have a class that contains a number of typedef'd variables, like so: class X{ typedef token TokenType; bool doStuff() { TokenType data; fillData(&data); return true; } }; Is there any way to override the typedef for TokenType in a derived class? N.B. This is NOT a good place to use templates (This is already a templ...

Typedef pointers a good idea?

I looked through some code and noticed that the convention was to turn pointer types like SomeStruct* into typedef SomeStruct* pSomeStruct; Is there any merit to this? ...

Templated namespaces and typedefs are illeagal -- workarounds?

I have a templated function fct that uses some complex data structure based on the template parameter. It also calls some helper functions (templated on the same type) that are in a separate helpers namespace and use the same complex data structure. Now it gets really ugly because we cannot make one typedef for the complex type that all ...

Internal typedefs in C++ - good style or bad style?

Something I have found myself doing often lately is declaring typedefs relevant to a particular class inside that class, i.e. class Lorem { typedef boost::shared_ptr<Lorem> ptr; typedef std::vector<Lorem::ptr> vector; // // ... // }; These types are then used elsewhere in the code: Lorem::vector lorems; Lorem::ptr lorem(...

2 C enum questions

Part 1 In C, is there any difference between declaring an enum like this: typedef enum{VAL1, VAL2,} firstEnum; and like this: enum secondEnum{Val1, Val2,}; Apart from the fact that when using secondEnum, you have to write: enum secondEnum...; Part 2 Also, am I right in thinking that the following is equivalent: enum{Val1, Val...

Forward declaration of a typedef in C++

Why won't the compiler let me forward declare a typedef? Assuming it's impossible, what's the best practice for keeping my inclusion tree small? ...

How can I typedef a function pointer that takes a function of its own type as an argument?

Example: A function that takes a function (that takes a function (that ...) and an int) and an int. typedef void(*Func)(void (*)(void (*)(...), int), int); It explodes recursively where (...). Is there a fundamental reason this can't be done or is there another syntax? It seems to me it should be possible without a cast. I'm really tr...

Forward declare a class's public typedef in c++

I'm trying to simplify a bunch of header file "include spaghetti" by using forward declarations and moving #includes into the implementation file. However, I keep coming upon the following scenario: //Foo.h #include "Bar.h" class Foo { public: void someMethod(Bar::someType_t &val); }; //Bar.h . . . class Bar { public: typedef std...

c++ typedef another class's enum?

So here's my problem: struct A { enum A_enum { E0, E1, E2 }; }; struct B { typedef A::A_enum B_enum; bool test(B_enum val) { return (val == E1); // error: "E1" undeclared identifier } }; I specifically do not want to say A::E1. If I try B_enum::E1 I receive a warning that it...

How can I remove the VS warning C4091: 'typedef ' : ignored on left of 'SPREADSHEET' when no variable is declared

This warning is triggered multiple times in my code by the same declaration, which reads : // Spreadsheet structure typedef struct SPREADSHEET { int ID; // ID of the spreadsheet UINT nLines; // Number of lines void CopyFrom(const SPREADSHEET* src) { ID = src->ID; ...

How come pointer to a function be called without dereferencing?

I have a weird typedef statement in a C++ program, generated by Py++. double radius(int); // function to be wrapped typedef double (*radius_function_type)(int); bp::def("radius", radius_function_type(&radius)); // bp::def is a function for wrapping What I figured out so far is that the above typedef statemnt is not of the type,...