Weird template compilation error with VisualStudio 2005

This is a discussion on Weird template compilation error with VisualStudio 2005 within the C++ Programming forums, part of the General Programming Boards category; Hi, Just encountered a very weird error while compiling a very simple class template. This does not compile: Code: #ifndef ...

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248

    Weird template compilation error with VisualStudio 2005

    Hi,

    Just encountered a very weird error while compiling a very simple class template.

    This does not compile:
    Code:
    #ifndef __MATRIX_
    #define __MATRIX_
    
    #include <fstream>
    #include <iostream>
    #include <valarray>
    
    namespace LinearAlgrebra
    {
    
        template<typename T> class Matrix
        {
        public:
    	Matrix();
      
        private:
    	size_t _nbrows;
    	size_t _nbcols;
    	
    	valarray<T> _elms; // vector of column vectors
    	
        }; // end class template
        
    };
    
    #endif
    with the messages
    1>d:\src\pluginlib\inc\LinearAlgebra/Matrix.h(25) : error C2143: syntax error : missing ';' before '<'
    1> d:\src\pluginlib\inc\LinearAlgebra/Matrix.h(27) : see reference to class template instantiation 'LinearAlgrebra::Matrix<T>' being compiled
    1>d:\src\pluginlib\inc\LinearAlgebra/Matrix.h(25) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>d:\src\pluginlib\inc\LinearAlgebra/Matrix.h(25) : error C2238: unexpected token(s) preceding ';'
    Does it somehow not recognize the 'valarray<T>' ? I really don't understand....
    Last edited by MarkZWEERS; 11-09-2008 at 10:20 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    Perhaps std::valarray
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    valarray, like all other elements of the C++ standard library, is in namespace std. You need to write std::valarray.

    You also need to include <cstddef> and write std::size_t. That one won't cause compilation errors on most compilers, but it's still needed for your program to be strictly correct.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248
    oh damn, what a stupid mistake.... shame on me!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  2. Specialising a member function with a template template parameter
    By the4thamigo_uk in forum C++ Programming
    Replies: 10
    Last Post: 10-12-2007, 04:37 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 11:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21