including templatized vector and vector

This is a discussion on including templatized vector and vector within the C++ Programming forums, part of the General Programming Boards category; why is it that I got this error, when I compile the code by using the -Dproject flag?: Code: /vehicle.h:21: ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    569

    including templatized vector and vector

    why is it that I got this error, when I compile the code by using the -Dproject flag?:

    Code:
    /vehicle.h:21: error: ‚project‚ has not been declared
    /vehicle.h:21: error: expected `{' before ‚vector‚
    /vehicle.h:21: error: expected initializer before ‚<‚ token
    /vehicle.h:33: error: ‚project‚ has not been declared
    /vehicle.h:33: error: expected `{' before ‚vector‚
    am I doing anything wrong? the code is attached below...
    The weird thing is that if I take out the #include <vector> in the vehicle.h file and then compile the file using -Dproject it works, however if I include it with athe #include <vector> it doesn't work... I just don't know why
    Attached Files Attached Files
    Last edited by -EquinoX-; 11-21-2009 at 10:47 PM.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    I recommend running it through the preprocessor only (-E with GCC), and you should find something like this:
    Code:
    namespace 1{
    
    template <class type, int n> class vector;
    and

    Code:
    class State : public 1::vector<double, 4> { };
    Use a convention for macro names that doesn't let them get mixed up with other identifiers (e.g macro names and only macro names are ALL CAPS).

    -----------

    Another thing:

    Code:
    template <class type, int n>
    bool checkSize(const vector<type, n>& v1, const vector<type, n>& v2)
    {
       try {
          if( v1.size != v2.size )
             throw "Operations of two vectors of not the same size!";
    	return true;
       }
       catch( char * str ) {
          std::cout << "Exception raised: " << str << std::endl;
       }
    }
    1) Don't use throw for flow control inside a function. Exceptions are thrown to indicate to the caller that something is wrong, otherwise you can just use normal flow control constructs:

    Code:
    template <class type, int n>
    bool checkSize(const vector<type, n>& v1, const vector<type, n>& v2)
    {
    
       if( v1.size == v2.size )
           return true;
       std::cout << "Exception raised: Operations of two vectors of not the same size!" << std::endl;
       //note the lack of return statement!?: did you mean: return false;?
    }
    2) Printing an error message and continuing as if nothing happened (in this case returning an indeterminate value) is not a particularly good error handling strategy. The caller will not know what happened in checkSize.

    3) If you need to throw exceptions, prefer throwing exception objects (preferable one defined in <stdexcept> or derived from those) over built-in types.
    Last edited by anon; 11-22-2009 at 04:13 AM.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

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