CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Location
    Texas, USA
    Posts
    1,206

    Vector gives compiler errors?

    Consider the following code:

    Code:
    //--Header-Files----------------------------------
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    #include    <vector>
    //------------------------------------------------
    
    
    //--Global-Variables------------------------------
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    double          CoordinateMultiplierX       = 0;        //Size of X axis increment in Pixels
    double          CoordinateMultiplierY       = 0;        //Size of Y axis increment in pixels
    int             MapX                        = 0;        //Size of Client Rectangle X
    int             MapY                        = 0;        //Size of Client Rectangle Y
    //------------------------------------------------
    
    
    //--Structures------------------------------------
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    struct Points {
        double x;
        double y;
        bool Invisible;                                 //TRUE = Move to, FALSE = Line to
        Points(double xx, double yy, bool i) {
            x = xx * CoordinateMultiplierX;
            y = yy * CoordinateMultiplierY;
            Invisible = i; } };
    //------------------------------------------------
    
    
    //--Vector-Declarations---------------------------
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    vector<Points>  MapPoints                   ;               //Contains points to draw Map Lines
    //------------------------------------------------
    Here are the errors my compiler gives. I'm using Visual Studio .NET 2003:

    Code:
    error C2143: syntax error : missing ';' before '<'
    error C2501: 'vector' : missing storage-class or type specifiers
    error C2065: 'MapPoints' : undeclared identifier

    Can someone please tell me why these errors occur? I can't seem to figure it out

  2. #2
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128
    Use std::vector<Points> MapPoints in your code instead. This is the compiler can't find vector in the global namespace. Thus, you need to specify the std namespace.

  3. #3
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    In addition...the following shows you the four different methods to map a namespace...
    Code:
    // Using the full member name, including the namespace it belongs to:
    std::cout << "Hello World";
    
    
    // By taking advantage of Using-Declarations:
    using std::cout;                             // This declares cout in the current
                                                 // scope as synonym for std::cout
    cout << "Hello World";
    
    
    // By taking advantage of Using-Directives:
    using namespace std;                         // Which specifies that the current
                                                 // scope can refer to names in the
                                                 // 'std' namespace without using
                                                 // full qualifiers. This is mostly
                                                 // used when porting legacy code.
    cout << "Hello World";
    
    
    // Using aliases:
    namespace X
    {
      namespace Y
      {
        class Z { ... };
      }
    }
    
    X::Y::Z                                      // The full qualifier for 'Z' is
                                                 // 'X::Y::Z'
    
    namespace w = X::Y;                          // This declares 'w' as an alias for
                                                 // namespace 'X::Y'
    
    w::Z                                         // Access 'Z' using 'w::Z'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured