2014-10-03 79 views
0

我明白爲什麼這不起作用,因爲子類不是前向引用,而是沿着這些行具有相同理論功能的東西嗎?正向聲明子類數組

這是我能不能轉發引用子陣列我會用的實現:

class_declare.h:

class parentClass{ 
    int i; 
}childClass[100]; 

someSource0.cpp:

include "class_declare.h" 

//manipulate values of the array - but can this refer to one that is forward declared 
//and not a new object? 
void dosomething(){ 
    childclass[1]=10; 
} 

someSource1.cpp :

include "class_declare.h" 

void dosomethingelse(){ 
    std::cout<<childclass[1]; 
} 

輸出:

謝謝!

+1

這裏沒有子類。有一個100個'parentClass'的數組,它被稱爲「childClass」。也許你需要[一本好書](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)? – molbdnilo 2014-10-03 14:45:39

+0

not * forward declare *,但只是* declare *:'extern parentClass childclass [100];'在頭文件和'parentClass childclass [100];'在一些cpp文件中 – 2014-10-03 14:54:05

+0

我明白我已經創建了一個類的數組類型,不管數組的錯誤標記,我想知道這是否可能。 – s33ds 2014-10-03 14:54:50

回答