typedef

"Expected initializer before '<' token" in header file

I'm pretty new to programming and am generally confused by header files and includes. I would like help with an immediate compile problem and would appreciate general suggestions about cleaner, safer, slicker ways to write my code. I'm currently repackaging a lot of code that used to be in main() into a Simulation class. I'm getting a c...

C++ template typedef

I have a class template<size_t N, size_t M> class Matrix { // .... }; I want to make a typedef which creates a Vector (column vector) which is equivalent to a Matrix with sizes N and 1. Something like that: typedef Matrix<N,1> Vector<N>; Which produces compile error. The following creates something similar, but not exactly what...

In Objective C, is there a way to call reference a typdef enum from another class?

It is my understanding that typedef enums are globally scoped, but if I created an enum outside of the @interface of RandomViewController.h, I can't figure out how to access it from OtherViewController.m. Is there a way to do this? So... "RandomViewController.h" #import <UIKit/UIKit.h> typedef enum { EnumOne, EnumTwo }EnumType; @i...

C++ using typedefs in non-inline functions

I have a class like this template< typename T > class vector { public: typedef T & reference; typedef T const & const_reference; typedef size_t size_type; const_reference at( size_t ) const; reference at( size_t ); and later in the same file template< typename T > typename vector<T>::const_reference ...

I cannot understand the point of this simple code.

I am doing this assignment, and there are some stuff (from start-up materials) that I cannot comprehend. typedef enum { NORTH, EAST, SOUTH, WEST, NUM_POINTS } Point; typedef Point Course[NUM_POINTS] ; I don't get the idea behind the last line , and how can I use it in the code? ...

typedef to store pointers in C

The Size of pointer depends on the arch of the machine. So sizeof(int*)=sizeof(int) or sizeof(int*)=sizeof(long int) I want to have a custom data type which is either int or long int depending on the size of pointer. I tried to use macro #if, but the condition for macros does not allow sizeof operator. Also when using if-else, typed...

cocoa Expected specifier-qualifier-list before struct

I read the other posted solutions to using structs and resolving the "Expected specifier-qualifier-list before struct" related errors, but those aren't working. Is it different in Objective C? Do I need to declare my struct somewhere else in the class? It gives me the error on the line where I declare the typedef. Here is how it look...

Calling cli::array<int>::Reverse via a typedef in C++/CLI

Here is what I'm trying: typedef cli::array<int> intarray; int main(){ intarray ^ints = gcnew intarray { 0, 1, 2, 3 }; intarray::Reverse(ints); // C2825, C2039, C3149 return 0; } Compilation resulted in the following errors: .\ints.cpp(46) : error C2825: 'intarray': must be a class or namespace when followed by '::' ...

C++ struct definition

Possible Duplicate: What does unsigned temp:3 means I just found this code in a book (was used in an example) typedef struct { unsigned int A:1; unsigned int B:1; unsigned int C:1; } Stage; What is the meaning of this structure definition? (the A:1;) ...

recursive typedef

Is the following allowed? typedef Foo<Bar> Bar; My compiler complains that 'class Bar' has a previous declaration as 'class Bar'. ...

C++ typedef for partial templates

Hi, i need to do a typedef like this. template< class A, class B, class C > class X { }; template< class B, class C > typedef X< std::vector<B>, B, C > Y; I just found that it is not supported in C++. Can someone advise me on how to achieve the same through alternative means? Thanks, Gokul. ...

Should I cast variables that use a typdef'd type?

If I have something like: typedef int MyType; is it good practice to cast the operands of an operation if I do something like this: int x = 5; int y = 6; MyType a = (MyType)(x + y); I know that I don't need to do that but wondering if it's better for intent/documentation/readability concerns. Or, should I just do: MyType a = x + ...

Accessing typedef from the instance

As in stl containers, why can't we access a typedef inside the class from the class instance? Is there a particular insight into this? When value_type was a template parameter it could help making more general code if there wasn't the need to specify the template parameters as in vector::value_type Example: class T { public: typ...

Dynamic creating of typedef

Hello, I'm creating event system. It's based under boost::signals. To make the work easier I'm using typedef for the function signatures. Everything is okey until I need creating of some new event trought event's system method. I have to create the typedef dynamically on given type to the template function. The problem is the name of ty...

typedef and incomplete type

Recently I am having many problem with typedef and incomplete type when I changed certain containers, allocators in my code. What I had previously struct foo;//incomplete type. typedef std::vector<foo> all_foos; typedef all_foos::reference foo_ref; Though not completely not sure whether the above lines are legal, but this worked on e...

function templates with class template typedef arguments

Hi, the following code is an example of something I'm trying to do in a large project: #include <iostream> #include <vector> // standard template typedef workaround template<typename T> struct myvar {typedef std::vector<T> Type;}; template<typename T> T max(typename myvar<T>::Type& x) // T max(std::vector<T>& x) { T y; y=*x.begin(...

vector of double[2] error

...

C++ Typedefs and operator overloading

If you define a type like typedef int MY_INT; and go on to overload, say, the adition operator of MY_INT like MY_INT operator+(MY_INT a, MY_INT b); will MY_INT a, b; a + b; be different from int A, B; A + B; ? Sorry for any syntax errors. I'm not near a compiler and I want to ask this before I forget about it. ...

Two-way inclusion of classes & template instances

Hi all, I'm having a problem when trying to compile these two classes (Army and General) in their own header files: #ifndef ARMY_H #define ARMY_H #include "definitions.h" #include "UnitBase.h" #include "UnitList.h" #include "General.h" class Army { public: Army(UnitList& list); ~Army(void); UnitBase& operator[](con...

Inserting <string, function pointer> into map

I'm having trouble with inserting some value_pairs into a map. Here's the basic idea. // private typedef Foo* (*Bar)( const std::string &x, int y ); typedef std::map<std::string, Bar> myMap; template<class T> Foo* DoThing( const std::string &x, int y ) { return new T( x, y ); } myMap m_map; // some map insertion code m_map.insert( ...