如果我宣佈一個函數在一個名爲ppmformat.h錯誤 '的extern' 後來 '靜態'
//file ppmformat.h
namespace imaging
{
Image * ReadPPM(const char * filename);
} //namespace imaging
文件...在ppmformat.cpp定義它
static imaging::Image * imaging::ReadPPM(const char *filename)
{
....
}
我得到以下錯誤:
'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。 –
如果我刪除靜態我採取「multiple :: definition :: ReadPPM(char const *)」的定義!你認爲包含文件有問題嗎? – madrugadas25845