Should C++ function default argument values be specified in headers or .cpp source files?

后端 未结 3 1298
渐次进展
渐次进展 2020-12-23 18:58

I am kind of new to C++. I am having trouble setting up my headers. This is from functions.h

extern void apply_surface(int, int, SDL_Surface *, SDL_Surface *         


        
3条回答
  •  执笔经年
    2020-12-23 19:25

    You make the declaration (i.e. in the header file - functions.h) contain the optional parameter, not the definition (functions.cpp).

    //functions.h
    extern void apply_surface(int, int, SDL_Surface *, SDL_Surface *,SDL_Rect * clip = NULL);
    
    //functions.cpp
    void apply_surface(int x, int y, SDL_Surface * source, SDL_Surface *
    destination,SDL_Rect *clip /*= NULL*/)
    {
        ...
    }
    

提交回复
热议问题