kernelK
kernelK

Reputation: 189

Error when compiling cpp file with g++

I have a CentOS 7 install running GCC 4.8.5 and I can successfully compile a cpp file named MyClass. I use the following command to compile the file:

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

When I run this command on a Centos 6.7 running GCC 4.4.7, I get the following error:

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*’

In my MyClass.h file, I have a private variable:

AVFormatContext   *pFormatCtx = NULL;

This error is repeated for any of the private variables that I initialize to NULL.

Is there an explanation for the difference I am encountering between my two CentOS installs?

This is the complete class:

    //
//  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__) */

Upvotes: 1

Views: 991

Answers (1)

Baum mit Augen
Baum mit Augen

Reputation: 50043

In-class initializers for non-static members like

AVFormatContext   *pFormatCtx = NULL;

are a C++11 feature. gcc4.4 is too old for that.

Upvotes: 2

Related Questions