0
我可以将C++代码重命名为.mm文件,并将项目中的所有.m文件更改为.mm但更改后的.m文件中有一个令人困惑的错误.mm将以下C++代码转换为对象C或C类
CFDictionaryRef routeChangeDictionary = inPropertyValue;
它说不能初始化变量类型`CFDictionaryRef(又名“const_CFDictionary *)类型的值‘常量无效*’
我一切重命名后不知道这样的错误。毫米
无论如何,我有原始的.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类?这很短。
你的意思是Objective-C? – snibbets
既没有对象C也没有C类。 – vikingosegundo