2016-04-28 77 views
-1

我正在創建一個Arduino庫,它爲我的個人項目提供了兩個構造函數,但由於某種原因,我不斷收到一個類型特定的錯誤,首先讓我告訴你結構如何。所以這裏是我的文件:C++測試庫時出錯

這是頭文件:

#ifndef iGA_H 
#define iGA_H 
class iGA { 
    public: 
     getParameters(int soundA[], int soundB[], int parentId[]); 
    private: 
     int _soundA[]; 
     int _soundB[]; 
     int _parentId[]; 
} 

cpp文件:

#include <iGA.h> 
iGA::getParameters(int soundA[], int soundB[], int parentId[]) 
{ 
    _soundA = soundA; 
    _soundB = soundB; 
    _parentId = parentId; 
} 

這該是多麼IM幾乎調用草圖中的構造,內設置()函數:

#include <iGA> 
iGA iga; 
void setup() { 
    iga.getParameters(r, r1 , r2); 
} 

,這裏是錯誤:

In file included from /home/bargros/Dropbox/iGA__NewBild/iGA__NewBild.ino:34:0:/home/bargros/Arduino/libraries/iGA/iGA.h:10:58: error: ISO C++ forbids declaration of 'getParameters' with no type [-fpermissive]getParameters(int soundA[], int soundB[], int parentId[]); 

我知道錯誤有事情做與參數類型或者也許我調用構造函數錯誤,但我也打過電話這樣的:

iGA iga = getParameters(etc,etc,etc); 

即時通訊相對較新的C++和IM有點無能至於這個錯誤告訴我什麼。有沒有人有任何想法,爲什麼發生這種情況?

+0

你的getParameters應該返回一些東西。**提示**:**之前應該有東西** iGA :: getParameters – Incomputable

+0

'getParameters(int soundA [],int soundB [],int parentId []);'至少應該是'void getParameters(int soundA [],int soundB [],int parentId []);'。 –

+0

試圖添加無效,仍然得到相同的錯誤 - 將嘗試@FirstStep建議。 – Bargros

回答

0

我相信兩個問題:

問題1:你的函數應返回正確的事情?如果只是爲了將參數分配給私有成員(您的情況爲setter而不是get),您可能需要將其設置爲void。將void添加到班級內部以及寫入其定義的適當位置。

第2期:我認爲你不能發送array[]作爲參數。我認爲你已經知道這個尺寸。相反,您需要發送指向數組第一個元素的指針以及整個數組的大小。然後,一旦接收到參數,對於每個私有成員,您將創建一個接收大小的新數組(或者直接填充私有成員),並通過使用收到的指針迭代接收的數組來填充值。

編輯:我剛纔檢查並通過int array[]應該沒問題。所以修復問題將解決您的問題。有關更多文檔,請參閱here

+0

問題1和2解決了我所有的問題,謝謝隊友。 – Bargros

+0

@bar高興它幫助:)請upvote,如果你發現它有用 –

0

在C++中,你必須明確的是一個功能不說,它返回void返回任何東西,你這樣做:

getParameters(int soundA[], int soundB[], int parentId[]); 

需求是

void getParameters(int soundA[], int soundB[], int parentId[]); 

iGA::getParameters(int soundA[], int soundB[], int parentId[]) 

需要爲

void iGA::getParameters(int soundA[], int soundB[], int parentId[])