gpt4 book ai didi

c++ - 使用g++编译cpp文件时出错

转载 作者:行者123 更新时间:2023-11-30 03:45:07 26 4
gpt4 key购买 nike

我有一个运行 GCC 4.8.5 的 CentOS 7 安装,我可以成功编译一个名为 MyClass 的 cpp 文件。我使用以下命令编译文件:

g++ -c -fpermissive  $(pkg-config --cflags --libs libavformat libavcodec libswscale libavutil) ./MyClass.cpp

当我在运行 GCC 4.4.7 的 Centos 6.7 上运行此命令时,出现以下错误:

In file included from ./MyClass.cpp:9:
./MyClass.h:70: warning: ISO C++ forbids initialization of member ‘pFormatCtx’
./MyClass.h:70: warning: making ‘pFormatCtx’ static
./MyClass.h:70: error: invalid in-class initialization of static data member of non-integral type ‘AVFormatContext*’

在我的 MyClass.h 文件中,我有一个私有(private)变量:

AVFormatContext   *pFormatCtx = NULL;

对于我初始化为 NULL 的任何私有(private)变量都会重复此错误。

是否有关于我在安装两个 CentOS 时遇到的差异的解释?

这是完整的类:

    //
// MyClass.h
// FFMpegPlayground
//

#ifndef __FFMpegPlayground__MyClass__
#define __FFMpegPlayground__MyClass__

#include <stdio.h>

#ifndef INT64_C
#define INT64_C(c) (c ## LL)
#define UINT64_C(c) (c ## ULL)
#endif

#ifdef __cplusplus
#define __STDINT_MACROS
#endif

extern "C" {
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
#include <libavutil/frame.h>
}

typedef enum {
K_STATUS_OK = 0,
K_CANT_OPEN_FILE = -1,
K_NO_STREAM_INFO = -2,
K_NO_VIDEO_STREAM = -3,
K_CODEC_UNSUPPORTED = -4,
K_CANT_COPY_CODEC = -5,
K_CANT_OPEN_CODEC = -6,
K_CANT_ALLOCATE_FRAME = -7,
K_SEEK_FAILED = -8,
K_UNABLE_TO_ACQUIRE_FRAME = -9
} MyClassStatus;

class MyClass{
public:
MyClass();
MyClass(const char * filePath);
MyClass(const char * filePath, double nScale);
~MyClass();

MyClassStatus getStatus();
void seekToFrame(int frame);
uint8_t* frameData();
uint8_t* nextFrameData();
uint8_t* copyOfNextFrameData();
int getFrameHeight();
int getFrameWidth();
int getCurrentFrame();
int getFrameDataSize();
long long getNumberOfFrames();

private:

bool fileIsLoaded;
uint8_t* createFrame();
int currentFrame;

void internalSeekToFrame(int frame);

MyClassStatus status;
AVFormatContext *pFormatCtx = NULL;
int i, videoStream;
AVCodecContext *pCodecCtxOrig = NULL;
AVCodecContext *pCodecCtx = NULL;
AVCodec *pCodec = NULL;
AVFrame *pFrame = NULL;
AVFrame *pFrameRGB = NULL;
int numBytes;
uint8_t *buffer = NULL;
struct SwsContext *sws_ctx = NULL;
uint8_t *_createdFrameData = NULL;


double preferredScale = 1.0;
};

#endif /* defined(__FFMpegPlayground__MyClass__) */

最佳答案

非静态成员的类内初始化器,例如

AVFormatContext   *pFormatCtx = NULL;

是 C++11 的特性。 gcc4.4 太旧了。

关于c++ - 使用g++编译cpp文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35048141/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com