tags:

views:

67

answers:

1

I keep getting the following link error on Visual Studio C++ 2010 Express,

shape.obj : error LNK2019: unresolved external symbol "class std::vector<class rectangle,class std::allocator<class rectangle> > __cdecl rectangleIzer::rectanglizePolygon(class std::vector<class rectangleIzer::myPoint,class std::allocator<class rectangleIzer::myPoint> >)" (?rectanglizePolygon@rectangleIzer@@YA?AV?$vector@Vrectangle@@V?$allocator@Vrectangle@@@std@@@std@@V?$vector@VmyPoint@rectangleIzer@@V?$allocator@VmyPoint@rectangleIzer@@@std@@@3@@Z) referenced in function "public: class std::vector<class rectangle,class std::allocator<class rectangle> > * __thiscall rectangleIzer::shape::rectanglizeCutouts(void)" (?rectanglizeCutouts@shape@rectangleIzer@@QAEPAV?$vector@Vrectangle@@V?$allocator@Vrectangle@@@std@@@std@@XZ)

Rectangle.h

#ifndef RECTANGLE_H
#define RECTANGLE_H

#include "myPoint.h"

using namespace std;
using namespace rectangleIzer;

class rectangle {
private:
    myPoint topLeft;
    myPoint bottomRight;

public:
    rectangle(){}
    rectangle(myPoint, myPoint);
    rectangle(float, float, float, float);
    myPoint getTopLeft() {return topLeft;}
    myPoint getBottomRight() {return bottomRight;}

    static float min(float a, float b) {
        if (a < b)
            return a;
        else
            return b;
    }

    static float max(float a, float b) {
        if (a > b )
            return a;
        else
            return b;
    }


};

#endif

Shape.h

#ifndef SHAPE_H
#define SHAPE_H

#include <vector>
#include "myPoint.h"
#include "rectangle.h"

using namespace std;
using namespace rectangleIzer;

namespace rectangleIzer {

    class shape {
    private:
        vector<myPoint> chaincode;

    public:
        shape() {}
        shape(vector<myPoint> chain) {chaincode = chain;}
        void getExtends(rectangle**);
        vector<rectangle>* rectanglizeCutouts();
    };
}

#endif
A: 

The linker can't find rectangleIzer::rectanglizePolygon. Did you define it? Vector here just happens to be the return type of the function it can't find. This has nothing to do with std::vector.

In general, here's how you can decypher these template error messages.

Step 1: Remove the garbage the linker puts at the end as the function's generated name:

class std::vector<class rectangle,class std::allocator<class rectangle> > __cdecl rectangleIzer::rectanglizePolygon(class std::vector<class rectangleIzer::myPoint,class std::allocator<class rectangleIzer::myPoint> >)"

Step 2: Remove references to std::allocator<t>:

class std::vector<class rectangle> __cdecl rectangleIzer::rectanglizePolygon(class std::vector<class rectangleIzer::myPoint>)"

Sometimes you'll have to remove more STL dross but once you're here you can clearly see the linker's looking for rectanglizePolygon, not anything related to std::vector.

Billy ONeal