C中多個實體類的問題

時間 2021-10-14 22:25:42

1樓:匿名使用者

public class class2

public class class3

看上面你寫的:public class class2

這句話是什麼意思呀,你在搞什麼,懂oo不?我擦!!!!

class2 k=new class2();

k.訪問不到

上面這一句你又想訪問什麼什麼,class2類中既沒屬性也是沒有方法。哥來教你寫吧,很簡單的,看下面:

public class myclass

//班號

public string cname //班級名稱

}public class student

//學號

public string sname //姓名

public string cno //班號

}public class combination

public student comstudent

}這樣你每次new combination時,就會new 一個班級類和一個學生類。不知道你這樣組合頂什麼用,估計是頂個鳥。哥再教你寫個實用的吧。

public class student

//學號

public string sname //姓名

}public class myclass

//班號

public string cname //班級名稱

public system.collections.generic.liststudentslist //在該班級下的學生清單

}public class combination

;student s2=new student()

;student s3=new student()

;system.collections.generic.listlist=new list();

myclass myclass = new myclass();}}

2樓:匿名使用者

你的“組合”內如果包含學生類、班級類,是需要例項化的。也即是new 學生類()、new 班級類()

關於C 中類的問題,關於C 中類别範本的問題

include 標頭檔案以 h 結尾 using namespace std template class complex template void complex set t a,t b 類函式在函式體外定義要寫template 類名後要加,下面同此 template void complex ...

c 類中成員函式的問題

1.你這基礎實在薄弱,基本概念都還沒懂 2.下面的void m f1 m m 是對類裡面 static void f1 m m 函式的實現。m m 的意思定義一個m的物件m.也就是這個函式的引數必須是一個m的物件。3.m p 5 q 10 這裡的定義兩個m物件 括號裡的值是傳遞給建構函式的,即呼叫此...

c中父類引用指向子類物件問題,c 中父類引用指向子類物件問題深究

記憶體分配肯定不一樣啦呀 a an new b 說明 在a堆裡面站了一個地址,然後在棧裡面存值 這個值是例項化new b 的值 b b new b 說明 在棧裡面直接開闢了一個b的空間!然後堆裡面有b的地址來指向直接開闢的空間!記憶體,堆疊?c 的東西這是,有的時候從c 的角度來考慮,不要管c 的指...