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
    Texas, USA

    Vector gives compiler errors?

    Consider the following code:

    #include    <vector>
    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
    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<Points>  MapPoints                   ;               //Contains points to draw Map Lines
    Here are the errors my compiler gives. I'm using Visual Studio .NET 2003:

    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
    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
    KY, USA
    In addition...the following shows you the four different methods to map a namespace...
    // 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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)