FAQ Database Discussion Community


C++ errors with typedefs in a templated class

c++,templates,visual-c++,typedef
I'm trying to write a simple templated event dispatcher but I get compiler errors that I don't understand and searching for it resulted in nothing helpful. I'm using Visual Studio 2013 express. Here's my code: template<typename T> class EventDispatcher { public: typedef void (EventHandler)(T event); EventDispatcher() { } ~EventDispatcher() {...

expected expression before ' '

c,structure,typedef
file.h typedef struct xyz{ unsigned int a; }__attribute__ ((packed,aligned(1))) abc,*ptr; file.c volatile unsigned int *add; add = &abc; ERROR : Expected Expression before 'abc' Can anybody help with this?...

C Unknown type name 'DATA'

c,compiler-errors,codeblocks,typedef
I don't really understand why I've been getting this error : Unknown type name 'DATA'. #include <stdio.h> #include <stdlib.h> typedef int DATA; #include "PriorityQueue.h" int main(){ int priority; DATA value; LINK *head; createEmpty(&head); add(&head, 1, 7); checkIfEmpty(head); add(&head, 5, 5); add(&head, 3, 4); deleteElement(&head, &priority, &value); add(&head, 1, 3); destroy(head);...

Error while trying to update array element

c,arrays,pointers,struct,typedef
I am working on an embedded platform which does not have debugging features. So it is hard to say what is the error source. I have defined in header file: typedef struct cm_packet { CM_Header Header; //header of packet 3 bytes uint8_t *Data; //packet data 64 bytes CM_Footer Footer; //footer...

Can the type returned by std::bind be default-constructed?

c++,c++11,bind,typedef,default-constructor
I can typedef the return type of a std::bind expression, but apparently the compiler is not happy with me calling the default-constructor of this type. Instead, I have to pass the exact same arguments that I did to std::bind in the first place (cf below); why? Am I doing this...

Access typedef in classes with an object, not the scope resolution operator (::)

c++,class,typedef
In the following code, when I try to access the typedef with an instantiated object, it gives me an error, when I access it using the scope resolution operator (::), the program works perfectly. I just wanted to know why. #include <iostream> class Types { public: typedef int Integer; };...

Expected Identifier - C [closed]

c,struct,typedef
I am having an issue with structs. Before each function declaration I get an error about an identifier. Errors occur before 'typedef', 'coords stackCreate', and 'coords stackPush' typedef struct coords * coordPtr { int x = -1; int y = -1; struct coords * next; }; coords stackCreate(int x, int...

Declaring a structure: typedef struct name name;

c,struct,typedef
We all know how to declare a structure in C: struct Label1{ /* variables */ } Label2; // As I learned But I want to know why this code works without declaring 'struct name': typedef struct name s_name; Or is in fact, does typing the code struct name; mean that...

Error : Expected expression before 'DATA /* : typedef struct DATA DATA */

c,struct,compiler-errors,linked-list,typedef
I don't know what's the problem here my code. I read some questions of others that had the same problem , but I didn't found an answer. When I try to compile I get this errors : ||In function 'main':| |35|error: expected expression before 'DATA'| ||In function 'lecture_data':| |59|error: expected...

Using a wrapper class for a typedef equivalent in Java; must I expose the class variable?

java,arraylist,typedef
I think I am missing something fundamental here. In writing an card-game app, I define a Card class, and then various collections of cards in this form: ArrayList<Card> cards; Now of course I can continue to use all the appropriate ArrayList methods. At some point I get tired of writing...

class object array inside struct

c++,arrays,class,struct,typedef
I need to put an array of class objects inside a struct. The class inside a header file: class aClass { private: int num; public: aClass(); ~aClass(); int getNum(); void setNum(int num); } The typedef inside a another header file #include "aClass.hpp" typedef struct { aClass* classObject[3]; } newType_t; At...

Constructor taking shared_ptr

c++,c++11,typedef,shared-ptr,make-shared
I have situation like this struct Foo { Foo(int x, int y) : x(x), y(y) { } int x, y; }; class Bar { public: typedef std::shared_ptr<const Foo> ConstFooPtr; typedef std::shared_ptr<Foo> FooPtr; Bar(int index = 0, FooPtr ptr = FooPtr()) : index_(index), ptr_(ptr) { } private: ConstFooPtr ptr_; int index_;...

What's the use of 'typedef in C'?

c,struct,typedef
There are 3 versions of a header file. version 1: typedef struct node { void* dataPtr; struct node* link; } NODE; version 2: without old type name 'node' (typedef oldTypeName newTypeName) typedef struct { void* dataPtr; struct* link; } NODE; version 3: without typedef struct { void* dataPtr; struct* link;...

Implications of typedef void FOO vs. #define FOO void in function signatures [duplicate]

c++,c,typedef,c-preprocessor
This question already has an answer here: void, VOID, C and C++ 3 answers While going through some source code that heavily mixes C and C++, I came across the following (slightly modified to protect the work of the company, the meaning remains the same): /* * Typedefs of...

accessing structure member using pointers

c,pointers,struct,typedef
I am a newbie in C. I am trying to create a typedef struct outside of main and then create a pointer of typedef. Then pass this pointer into another function. However I am getting error. It is driving me crazy .Thank you very much in advance.. typedef struct rem_info...

C - dynamic array of typedef struct with in-function malloc

c,arrays,pointers,malloc,typedef
I'm stuck again and have huge issues understanding whats going on in my following code examples: //Filename main.c #include<stdio.h> #include "entries.h" int main(){ playerEntry *Entry; printf("Number of Entries: %d",readPlayerList(&Entry)); return 0; } It simply calls the function and prints out the result and should be able to handle the entries...

typedef struct name name without a subsequent struct definition

c++,c,struct,typedef,elf
I found the following code at lines 153-154 in the libelf.h of the libelf library: /* Descriptor for the ELF file. */ typedef struct Elf Elf; I was looking for a struct definition of Elf but did not find it. Later in the code, Elf is used, e.g. /* Return...

C function pointer callback as struct member with “self” reference parameter [duplicate]

c,struct,function-pointers,typedef,self-reference
This question already has an answer here: forward declaration of a struct in C? 2 answers I want to create a task struct containing a function pointer to a callback to execute said task. The task contains the parameters so I would like to pass a "this/self" pointer of...

typedef equivalent in C# to use C++ DLL

c#,c++,dll,typedef,dllimport
I'm trying to call a C++ structure, exported to a DLL, from C#-Code This is the C++ interface to the Method I want to call: typedef void *Handle; typedef void (*Callback)(Info *info); typedef void (*Timeout)(Info *info); typedef struct { WORD port; WORD flag; char name[16]; } Info; __declspec(dllexport) Handle open(Info...

Dereferencing Pointer to incomplete type Linked List - C

c,pointers,struct,linked-list,typedef
I've been trying to figure this out for a while now, but cannot find a solution. I am building a linked list and when I try to pass the list as a pointer to anything I get an error: Dereferencing Pointer to incomplete type. Here is my struct declaration typedef...

typedef struct on Arduino : variable does not name a type

c++,c,struct,arduino,typedef
I want to make a typedef struct ( or similar, if i can't ) on arduino mega for 20 sensors, but i have a error and i don't understand why. Is it from arduino compilation or from my code ? Do you think that i must to put my code...

Possible side effects of doing a typedef of a struct to an array of one element in C

c,typedef,gmp,ruby-c-extension
I came across this code. typedef __mpz_struct MP_INT; typedef __mpz_struct mpz_t[1]; Here the struct __mpz_struct is a struct that is typedefed to an array of single element. I understand that this is a trick to pass by reference in C. Then mpz_t has been used as a type to declare...

C function typedef: defining function without parameter list

c,typedef,function-declaration
I have program that has dozens (maybe over 100) functions with same parameter list and return type. I also may want to add parameter to those functions. So, is there any way to define those functions with typedef prototype (with parameter list)? example: I have dozens of functions int f1...

Not known implementation of typedef in C

c,typedef
I am confused about this example: typedef int32_t voltage_dc_estimate_t[1]; Everything is OK but that [1] at the end of the type definition confuse me. Could someone please help me to understand that situation?...

Writing C++ API - how to keep external references to API internal objects?

c++,vector,reference,typedef,encapsulation
So I'm writing an API in C++ to be used in another GUI application I'll be writing. The API will allow the user to create instances of "MyObject" and modify the properties of that object, but the object itself will not be exposed to the client, only an ID to...

How a struct being typedef-ed to multiple names?

c,struct,typedef
I've recently started to study about structs and pointers but there is something I didn't fully understand about the design of a struct. I understand the declaration of the struct i.e typedef struct Alias and its content, but I do not understand Get_noAllyp and *no_getOf at the end of the...

How to use typename instead of typedef?

c++,templates,c++11,typedef,typename
I have the following code snippet: template <class T> int foo(T (*f)()) { typedef T (*func)(); typedef functor<T, func> F; //this line // ... } As you can see, I use typedef for a function pointer (func), but I want to remove it to simplify my code. I tried this:...

Function does not recognize typedef argument

c,function,struct,typedef,argument-passing
okay, ive searched a solution for like two days now but i couldnt find whats going wrong with my code. ;( The task is simple: define a new type using typedef and have a function read out lines of this new type from a file into an array of again...

deduce template argument for typedef'd function pointer

c++,templates,function-pointers,typedef
Is there a way to deduce a template argument for a function pointer when using a typedef? My sample code is: struct A {}; void func(const A&) {}; template <typename T> struct FuncPtr { typedef void(*Type)(const T&); }; void f_(FuncPtr<A>::Type) {} template <typename T> // I'd like to hide the...

type-conversion in one function in C

c,function,struct,type-conversion,typedef
I have one doubt, could it be possible to create one typedef struct whatever and then if one function requires: void function(char * something); when you call the function in main program write: function((char *) whatever); is that correct? Thank you!...

use typedef type as a function return type [duplicate]

c++,typedef
This question already has an answer here: Where and why do I have to put the “template” and “typename” keywords? 6 answers I tried to use a typedef type as a return type for my member function, I don't know why it is giving me this "LinkedList" is not...

When I use typedef or using for an int, how much is it still an int?

c++,typedef,using
I tried the following: using Idx = int; array<Value, N> arr; for(Idx i = 0; i < N; i ++){ arr[i].doSomething(); } I expected that the compiler would issue a warning or an error when I try to use Idx as if it was an int. But it does not....

typedef struct in header and dereference pointer to incomplete type

c,pointers,struct,typedef
I'm quite rusty in C, but I think I'm having issues understanding the proper usage of using typedefs in headers, defining the actual struct's structure in the implementation file, and then using the struct in a third file. I wrote a queue data-structure that has a type defined as such:...

alias of a function template

c++,templates,typedef,using
I have created a CPU dispatcher which compiles the same functions with different compile options into different object files. In order for my code to access the same functions in different object files I need to give the functions in each object file a different name. In C (or C++)...

Typedef usage from one header file in second header file

c,project,typedef
Basically, I need to have typedef in one header file and use it on another header. myType.h: #ifndef deque_H #define deque_H #include "deque.h" typedef int intDef; #endif deque.h: #ifndef deque_H #define deque_H #include "myType.h" typedef struct dequeNode *link; struct dequeNode{ intDef data; link next; //count }; #endif I want to...

Passing defined type in main to header in C

c,header,typedef
So, as the title says, I am supposed to define a type in main file and, somehow, pass it to header. I tried to do that in any way, but I am out of ideas. I define it like this: "typedef int DATA;" and use it in header as a...

Cannot write data to struct

c,parsing,pointers,typedef,ini
qq4all. I have a task - write config parser for syntax like this: [module] name = first imitationType = first [module] name = second imitationType = second etc. I found pretty config parser - inih, but I can't force it to work as I want. Here my code, writed over...

c++11 typedef function pointer with trailing return type

c++11,function-pointers,typedef,trailing-return-type
I have been trying to clean up an inherited code base. It makes extensive use of template functions that include a trailing return type. It also includes a lot of function pointers to non-templated, non-member functions. During the clean up I discovered that code equivalent to the following works under...

Initialization of a typedef like a struct

c++,struct,typedef
Here is a code snippet: typedef struct foo { int i; int o; } foo; int main() { foo bar2 = { .i = 42; .o= 24; }; foo bar1; bar1.i = 42; bar1.o = 24; } I am trying to initialize the variable bar2 within the declaration, but it...

Using a function to alter typedef fields when individual structs are identified using an array

c,arrays,function,struct,typedef
This seems to be a very specific question that I'm having trouble finding any sort of answer. I'm attempting to use a typedef struct to store user information. Im using the format cust[x].firstName etc. to differentiate from one customer to another. Since I'm defining this struct in the header, it's...

How can I pass N number of generic arguments to a typedef function pointer?

c++,generics,typedef
I have this typedef function pointer plot: typedef void(*plot)(); How can I pass a generic argument to it (Something like this): template<typename T> typedef void(*plot)(T); And then, how can I pass N number of generic arguments to it? template<typename T> typedef void(*plot)(T ...); ...

When is a type equal (template specialization)?

c++,templates,typedef,using
I store a configuration as a type: using CONFIG1 = Config<x, y, z>; using CONFIG2 = Config<a, b, c>; using CONFIG3 = Config<x, y, z>; For each config, there's a class template specialization, which does some more configuration work: template <class CONFIG> MyClass; template <> MyClass<CONFIG1>{...} template <> MyClass<CONFIG2>{...} template...

Usage of typedef on function

c,function,typedef
What is the difference between the following function typedef: typedef void tbl_opt (void *tbl_item, void *tbl_param); // 1 typedef void *tbl_opt (void *tbl_item, void *tbl_param); // 2 typedef void (*tbl_opt) (void *tbl_item, void *tbl_param); // 3 typedef (void *) (*tbl_opt) (void *tbl_item, void *tbl_param); // 4 Usually, I use the...

Combining multiple template classes to one class using typedef

c++,templates,macros,typedef
I have the following piece of code. Let us have the function declaration and implementation seperate. #include <iostream> class Y1 {}; class Y2 {}; template <class T1, class T2> class A { public: explicit A(); void foo() const; int bar() const; }; template <class T1, class T2> A<T1, T2>::A() {}...

c++ typedef/type substitution for enumeration class

c++,c++11,enums,typedef,enum-class
As far as I am aware at the moment it is not possible to do a typedef of the C++11 enum class. I would like to know if there is any other way I can reduce the length of the name of an enum variable when referring to it outside...

How to make types for indexing

c++,typedef
I have something like: Array definition: array<array<Value, N_FOO_PER_BAR>, N_BAR> arr; Access function: Value getFoo(int barIdx, int fooIdx){ return arr[barIdx][fooIdx]; } For-loop: for(int i = 0; i < N_BAR; i ++){ for(int j = 0; j < N_FOO_PER_BAR; j ++){ arr[i][j].doSomething(); } } Problem: Indices for foo and bar can easily...

In search of understanding a typedef

c++,typedef
I have a program where I'm dynamically loading a dll and using a 'factory' function to get a class instance. (I actually pulled this from a post I read somewhere on the Net and just blindly used it.) To do this, I have a code snippet like the following: typedef...

conversation with typedef variable in c++

c#,c++,variables,dll,typedef
i have c++ type definition like this typedef void* ScreenNode; and use it in my c++ code like this ret = InitNode("factory", &g_screen_node, 128, 128, EN_C1Dev); **EN_C1Dev is a ENUM my typedef variable is a void pointer and InitNode return a value by changing pointer value "g_screen_node". now i use...

Eliminate use of typedef in a linked list program

c,typedef
I am studying linked lists and (among other, simpler implementations) I encountered this example: typedef struct ListNode_tag { int data; struct ListNode_tag * next; } ListNode; /* linked list */ typedef ListNode * slist; void slistInsert (slist * lp, int t) { ListNode * n = (ListNode *) malloc(sizeof(ListNode)); n->data...

typedef pointer using fgets to input data, but takes last fgets

c,malloc,typedef,fgets,calloc
I'm trying to read postal codes from a file into an Object * array. file includes 123 Anywhere kirkland CA 99223 my .h file looks like typedef struct { char *street; char *city; char *state; int zip; }Address; my filling the array Address * fillArray(int * total, FILE * fin)...

Typedef equivalence for a pointer to struct

c++,typedef
I got this implementation of a struct: struct NodoQ { Etype elem; NodoQ *sig; }; Is this code below, typedef NodoQ *PtrNodoQ; PtrNodoQ ppio, fin; the same as this one? NodoQ* ppio; NodoQ* fin; ...