C++ コードの名前を .mm ファイルに変更し、プロジェクト内のすべての .m ファイルを .mm に変更できますが、.mm に変更した後、.m ファイルの 1 つに紛らわしいエラーがあります。
CFDictionaryRef routeChangeDictionary = inPropertyValue;
「const void*」型の値で変数型「CFDictionaryRef (別名「const_CFDictionary*)」を初期化できません」と表示されました
すべての名前を .mm に変更した後、そのようなエラーはわかりません
とにかく、私は元の .CPP ファイル MeterTable.h を持っています
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
class MeterTable
{
public:
MeterTable(float inMinDecibels = -80., size_t inTableSize = 400, float inRoot = 2.0);
~MeterTable();
float ValueAt(float inDecibels)
{
if (inDecibels < mMinDecibels) return 0.;
if (inDecibels >= 0.) return 1.;
int index = (int)(inDecibels * mScaleFactor);
return mTable[index];
}
private:
float mMinDecibels;
float mDecibelResolution;
float mScaleFactor;
float *mTable;
};
MeterTable.CPP #include "MeterTable.h"
inline double DbToAmp(double inDb)
{
return pow(10., 0.05 * inDb);
}
MeterTable::MeterTable(float inMinDecibels, size_t inTableSize, float inRoot)
: mMinDecibels(inMinDecibels),
mDecibelResolution(mMinDecibels / (inTableSize - 1)),
mScaleFactor(1. / mDecibelResolution)
{
if (inMinDecibels >= 0.)
{
printf("MeterTable inMinDecibels must be negative");
return;
}
mTable = (float*)malloc(inTableSize*sizeof(float));
double minAmp = DbToAmp(inMinDecibels);
double ampRange = 1. - minAmp;
double invAmpRange = 1. / ampRange;
double rroot = 1. / inRoot;
for (size_t i = 0; i < inTableSize; ++i) {
double decibels = i * mDecibelResolution;
double amp = DbToAmp(decibels);
double adjAmp = (amp - minAmp) * invAmpRange;
mTable[i] = pow(adjAmp, rroot);
}
}
MeterTable::~MeterTable()
{
free(mTable);
}
C++ ファイルを実際のオブジェクト C クラスに書き直すアイデアはありますか? かなり短いです。