2012-10-16 157 views
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類?這很短。

+0

你的意思是Objective-C? – snibbets

+0

既沒有對象C也沒有C類。 – vikingosegundo

回答

0

當我混合使用C++和Objective-C代碼時,我已經非常難以找到像這樣的問題。如果您將文檔設置爲XCode中屬性的Objective C++,請確保您對調用C++代碼的Objective-C文件執行相同的操作,並且包含所需的C++頭文件。

我有過這個之前,它會得到最奇怪的錯誤信息。如果情況並非如此,請在這裏抱怨答案。當有多個頭文件包括C++類的引用時,有時會更難追查。將所有文件(如果它不是一個大項目)設置爲「Objective C++」並不會造成任何傷害。