typename

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...

Help storing an intrusive_ptr of a template class in a std::map

I have a small template class of type Locker contained within a boost::intrusive_ptr that I want to store inside a std::map: template <typename T> bool LockerManager<T>:: AddData(const std::string& id, T* pData) { boost::intrusive_ptr<Locker<T> > lPtr(Locker<T>(pData)); // Line 359 - compiles mMap.insert(make_pair(id, lPtr)); /...

How to take a typename as a parameter in a function? (C++)

I need to be able to pass a typename as a parameter: int X = FileRead(file, 9, char); The concept is for FileRead(std::fstream, int pos, ???) to read pos*sizeof(whatever the type is) to get the desired position. I tried templates: template<typename T> T FileRead(std::fstream file, int pos, T type) { T data; file.read(reinter...

C++ Get name of type in template

I'm writing some template classes for parseing some text data files, and as such it is likly the great majority of parse errors will be due to errors in the data file, which are for the most part not written by programmers, and so need a nice message about why the app failed to load e.g. something like: Error parsing example.txt. Val...

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++ Template Specialization

The following template specialization code template<typename T1, typename T2> void spec1() { } Test case 1 template< typename T1> //compile error void spec1<int>() { } Test case 2 template< typename T2> //compile error void spec1<int>() { } generates a error C2768: 'spec1' : illegal use of explicit template arguments compil...

C++ templated constructor won't compile

How come I can't instantiate an object of type Foo with above constructor? I have a class Bar that uses an internal typedef (as a workaround for "template typedefs") and intend to use it in a constructor as below (CASE 1). However, I don't seem to get it to compile. Is this legal C++? CASE 2 seems to suggest the problem is related to th...

C++ Template class using STL container and a typedef

Hi, I have a class looking like this: #include <vector> #include "record.h" #include "sortcalls.h" template< typename T, template<typename , typename Allocator = std::allocator<T> > class Cont = std::vector> class Sort: public SortCall { This code is working and I'm calling it like this from other classes: Comparator c; // c...

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++ typename of member variable

hello everybody Is it possible to get typename of a member variable? For example: struct C { int value ; }; typedef typeof(C::value) type; // something like that? Thanks ...

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 ...

Academic question: typename

Possible Duplicate: Why do I need to use typedef typename in g++ but not VS? Hi, recently I accounted with a "simple problem" of porting code from VC++ to gcc/intel. The code is compiles w/o error on VC++: #include <vector> using std::vector; template <class T> void test_vec( std::vector<T> &vec) { typedef std::ve...

Passing an iterator to a function

Looking through the source code of a binary tree,I find the following function: //definition of BTR,in case you'd want to know template< class Type> struct BTR { // The item saved to that specifiec position into the tree Type value; // Points to the left leaf BTR<Type>* left; // Points to the right leaf ...

What is the purpose of "typename" in C++

Possible Duplicate: Officially, what is typename for? When I use template <typename TMap> typename TMap::referent_type * func(TMap & map, typename TMap::key_type key) { ... } what is the purpose of the two "typename"'s on the second line? It seems to trigger a compile-time warning (VS2008: C4346) but it's only a "do you c...

vector template conflicting declaration

I'm trying to implement a function that allows me to make a call like this // vec5 is a vector of tuples in my case // some code that to declare and fill vec5 columnViewOfTuple<0>(vec5); I implemented such function as follows template<int N> struct myfunction { template<typename T, typename R> std::vector<R> opera...

Errors in simple template code

template <class T> struct ABC { typedef typename T* pT; }; int main(){} The above piece of code gives errors expected nested-name-specifier before 'T' expected ';' before '*' token What is wrong with the code sample? ...

c++ templates without "typename" or "class"

hello! i'm used to write templates like this: template<typename T> void someFunction(SomeClass<T> argument); however - now I encountered templates in another thread written like this: template<U> void someFunction(SomeClass<U> argument); as far as i know one can use "typename" and "class" interchangably (except for some details re...