//file ppmformat.h
namespace imaging
{
Image * ReadPPM(const char * filename);
} //namespace imaging
ppmformat.hという名前のファイルに関数を宣言...と私が得る
static imaging::Image * imaging::ReadPPM(const char *filename)
{
....
}
ppmformat.cppでそれを定義した場合次のエラー:
'imaging::Image* imaging::ReadPPM(const char*)' was declared 'extern' and later 'static' [-fpermissive]
//ppmformat.h
#ifndef _PPM
#define _PPM
#include "Image.h"
namespace imaging
{
/*! Reads a PPM image file and returns a pointer to a newly allocated Image object containing the image.
*
* \param filename is the null-terminated string of the name of the file to open.
*
* \return a pointer to a new Image object, if the read operation was successful, nullptr otherwise.
*/
Image * ReadPPM(const char * filename);
} //namespace imaging
#endif
//ppmformat.cpp
#include <iostream>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include <string>
#include <fstream>
#include "ppmformat.h"
using namespace std;
imaging::Image * imaging::ReadPPM(const char *filename)
{
......
}
//Image.h
#ifndef _IMAGE
#define _IMAGE
#include "Color.h"
#include <iostream>
namespace imaging
{
class Image
{
....
}
}
//Image.cpp
#include <iostream>
#include "Color.h"
#include "Image.h"
....
//end of Image.cpp
//Color.h
#ifndef _COLOR
#define _COLOR
namespace imaging
{
Class Color
{
....
}
}
なぜソースファイルに 'static'関数を定義しますか? –
良い質問、upvoted。 –
静的を削除する場合、 "imaging :: ReadPPM(char const *)"の多重定義を取る!インクルードファイルに問題があると思いますか? – madrugadas25845