C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了c – 未解决的外部问题大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个解决的外部符号错误,这让我疯狂.简而言之,我有一个SDL_Surfaces包装类(‘DgSurface’)和一个加载和存储DgSurfaces(‘DgSurfaceList’)的类.尝试在我的项目中包含DgSurfaceList文件时出现链接问题.这是我的课程:

文件“DgSurface.h”包含DgSurface类声明:

#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”包含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,0);

    return *this;
}

这个类似乎工作正常,并按预期执行(但是,一如既往,我愿意接受反馈:).

“DgSurfaceList.h”包含DgSurfaceList类声明:

#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定义:

#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()

现在,如果我在cpp文件中注释掉DgSurfaceList :: GetImage()定义,DgSurfaceList似乎工作正常并正确存储图像.更具体地说,仅当我在上述函数中包含for循环时才会出现链接错误.会是什么呢?

其他信息:

错误

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 express 2010

解决方法

CrtDbgReport仅在C运行时库的调试版本中定义.因此,您可能正在编译调试模式,但链接到库的发行版本.另一种可能性是您在发布模式下进行编译,但是您定义的某个宏导致编译std :: list的调试版本.

大佬总结

以上是大佬教程为你收集整理的c – 未解决的外部问题全部内容,希望文章能够帮你解决c – 未解决的外部问题所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。