2012-08-12 49 views
7

मेरे पास एक अनसुलझे बाहरी प्रतीक त्रुटि है जो मुझे पागल कर रही है। संक्षेप में, मेरे पास SDL_Surfaces ('DgSurface') के लिए एक रैपर क्लास है और DgSurfaces ('DgSurfaceList') को लोड और स्टोर करने के लिए एक क्लास है। मेरी परियोजना में DgSurfaceList फ़ाइलों को शामिल करने का प्रयास करते समय लिंक समस्या उत्पन्न होती है। यहाँ मेरी वर्ग हैं:अनसुलझा बाहरी

#ifndef DGSURFACE_H 
    #define DGSURFACE_H 

    #include "SDL.h" 
    #include <string> 

    class DgSurface 
    { 
    public: 

     //Constructor/destructor 
     DgSurface(std::string N, SDL_Surface* I): image(I), name(N) {} 
     DgSurface() {name = ""; image = NULL;} 
     ~DgSurface(); 

     //Copy operations 
     DgSurface(const DgSurface&); 
     DgSurface& operator= (const DgSurface&); 

     //Data members 
     std::string name;  //The name of the image 
     SDL_Surface* image;  //The image 
    }; 

    #endif 

cpp फ़ाइल "DgSurface.cpp" contatins DgSurface परिभाषाएँ:

#include "DgSurface.h" 
#include "SDL.h" 

//-------------------------------------------------------------------------------- 
//  Constructor 
//-------------------------------------------------------------------------------- 
DgSurface::DgSurface(const DgSurface& other) 
{ 
    //Copy name 
    name = other.name; 

    //Create new SDL_Surface 
    image = SDL_ConvertSurface(other.image, other.image->format, 0); 
} 


//-------------------------------------------------------------------------------- 
//  Destructor 
//-------------------------------------------------------------------------------- 
DgSurface::~DgSurface() 
{ 
    SDL_FreeSurface(image); 
} 


//-------------------------------------------------------------------------------- 
//  Assignment operator 
//-------------------------------------------------------------------------------- 
DgSurface& DgSurface::operator= (const DgSurface& other) 
{ 
    // if same object 
    if (this == &other) 
     return *this; 

    //Copy name 
    name = other.name; 

    //Create new SDL_Surface 
    image = SDL_ConvertSurface(other.image, other.image->format, 0); 

    return *this; 
} 

हेडर फाइल "DgSurface.h" DgSurface वर्ग घोषणा-पत्र शामिल

यह कक्षा ठीक काम करने लगती है और उम्मीद के अनुसार प्रदर्शन करती है (हालांकि, हमेशा के रूप में, प्रतिक्रिया के लिए खुला :) :)।

"DgSurfaceList.h" DgSurfaceList वर्ग घोषणाओं में शामिल हैं:

#include "SDL.h" 
#include "SDL_image.h" 
#include <list> 
#include <string> 
#include "DgSurface.h" 
#include "DgSurfaceList.h" 


//-------------------------------------------------------------------------------- 
//  Load an image from file 
//-------------------------------------------------------------------------------- 
SDL_Surface* DgSurfaceList::LoadImage(std::string filename) 
{ 
    //Loads an image from file, returns SDL_surface* 
    ... 

} //End:DgSurfaceList::LoadImage() 


//-------------------------------------------------------------------------------- 
//  Add a DgSurface to the list 
//-------------------------------------------------------------------------------- 
bool DgSurfaceList::AddImage(std::string location, std::string name) 
{ 
    //Load the image 
    DgSurface temp(name,LoadImage(location)); 

    //If there was an error in loading the image 
    if(temp.image == NULL) 
     return false; 

    //If everything loaded fine, place a copy into imlist 
    imlist.push_back(temp); 

    return true; 

} //End: DgSurfaceList::AddImage(); 


//-------------------------------------------------------------------------------- 
//  Searches imlist for an image, returns a pointer to a SDL_Surface 
//-------------------------------------------------------------------------------- 
SDL_Surface* DgSurfaceList::GetImage(std::string S) const 
{ 
    std::list<DgSurface>::const_iterator i; 

    //Search imlist for DgSurface of the same name 
    for (i = imlist.begin(); i != imlist.end(); i++) 
    { 
     if (S.compare((*i).name) == 0) 
      return (*i).image; 
    } 

    //Return Null if name not found 
    return NULL; 

} //End:DgSurfaceList::GetImage() 

अब, अगर मैं DgSurfaceList बाहर टिप्पणी GetImage :::

#ifndef DGSURFACELIST_H 
#define DGSURFACELIST_H 

#include "SDL.h" 
#include <list> 
#include <string> 
#include "DgSurface.h" 


class DgSurfaceList 
{ 
    public: 
     //Constructors/destructor 
     DgSurfaceList() {} 
     ~DgSurfaceList() {} 

     //Functions 
     bool AddImage(std::string location, std::string name); 

     //Return Functions 
     SDL_Surface* GetImage(std::string S) const; 

    private: 
     //Data members 
     std::list<DgSurface> imlist; //The list of DgSurfaces 

     //Functions 
     SDL_Surface* LoadImage(std::string filename); 
}; 


#endif 

और अंत में "DgSurfaceList.cpp" DgSurfaceList निर्धारणों वाली() cpp फ़ाइल में परिभाषा, DgSurfaceList ठीक काम करता है और छवियों को सही ढंग से स्टोर करता है। अधिक विशेष रूप से, लिंक त्रुटि केवल तब उत्पन्न होती है जब मैं उपर्युक्त फ़ंक्शन में लूप को शामिल करता हूं। यह क्या हो सकता है?

अन्य जानकारी:

त्रुटि:

unresolved external symbol __imp___CrtDbgReportW referenced in function "public: class 
DgSurface const & __thiscall std::_List_const_iterator<class std::_List_val<class 
DgSurface,class std::allocator<class DgSurface> > >::operator*(void)const " 

कोडिंग पर्यावरण: Visual C++ 2010

उत्तर

11

CrtDbgReport व्यक्त केवल सी रन टाइम पुस्तकालय की डिबग संस्करण में परिभाषित किया गया है। तो शायद आप डीबग मोड में संकलित कर रहे हैं लेकिन पुस्तकालय के रिलीज संस्करण से जुड़ रहे हैं। एक और संभावना यह है कि आप रिलीज मोड में संकलित कर रहे हैं, लेकिन आपके द्वारा परिभाषित कुछ मैक्रो को std :: सूची के डीबग संस्करण को संकलित करने का कारण बन रहा है।

+3

धन्यवाद, मैं गुण-> सी/सी ++ -> कोड जेनरेशन-> रनटाइम लाइब्रेरी को एमटी डीबग डीएलएल में सेट करता हूं और अब संकलित कर सकता हूं। मुझे यकीन नहीं है कि ऐसा क्यों है, लेकिन इसमें देखेंगे। – Frank

+2

मुझे भी बूस्ट और ओपनसीवी का उपयोग करके यह समस्या थी। _DEBUG या NDEBUG झंडे से संबंधित संभावित स्पष्टीकरण हैं, मेरे मामले में उनके पास इस मुद्दे पर कोई प्रभाव नहीं है। दोनों धन्यवाद। –

+1

एनडीईबीयूजी को _DEBUG को बदलना हमारे हालिया सिरदर्द को हल करता है। धन्यवाद! – Jon