簡體   English   中英

從C ++調用C函數,“無匹配函數”錯誤

[英]Calling a C function from C++, “no matching function” error

我已經定義了以下頭文件(在C中),省略了函數實現,因為不需要:

#ifndef FFMPEG_MEDIAMETADATARETRIEVER_H_
#define FFMPEG_MEDIAMETADATARETRIEVER_H_

#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/dict.h>

int setDataSource(AVFormatContext** pFormatCtx, const char* path);

#endif /*FFMPEG_MEDIAMETADATARETRIEVER_H_*/

在C ++中,我定義了第二個頭文件:

#ifndef MEDIAMETADATARETRIEVER_H
#define MEDIAMETADATARETRIEVER_H

using namespace std;

extern "C" {
  #include "ffmpeg_mediametadataretriever.h"
}

class MediaMetadataRetriever
{
public:
    MediaMetadataRetriever();
    ~MediaMetadataRetriever();
    int setDataSource(const char* dataSourceUrl);
};

#endif // MEDIAMETADATARETRIEVER_H

在,mediametadataretriever.cpp中我定義了以下函數:

int MediaMetadataRetriever::setDataSource(
    const char *srcUrl)
{
    // should call C function
    AVFormatContext* pFormatCtx;
    return setDataSource(&pFormatCtx, srcUrl);
}

當我嘗試在Eclipse中編譯這個(C ++)項目時,我得到一個“No matching function call ...”錯誤,該錯誤與:

return setDataSource(&pFormatCtx, srcUrl);

如果我注釋掉了這個電話,代碼編譯得很好:

int MediaMetadataRetriever::setDataSource(
    const char *srcUrl)
{
    return 0;
}

這似乎是一個鏈接問題,有誰知道我做錯了什么?

該上下文中的setDataSource是成員函數的名稱。 要調用自由函數,請嘗試完全限定其名稱:

return ::setDataSource(&pFormatCtx, srcUrl);
//     ^^

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM