在.h文件中一個類的定義,該類擁有多個方法和屬性:classTest1{public:Test1(intn);voidset(int,int,int);intisLeapYear();voidprint();private:intnum;intmonth;intday;intyear;doublelength;};就是我在main函數(shù)中獲取到了類Test1實例t1了,如何才能知道這個實例中有哪些方法和屬性?這些方法和屬性有doc嗎?怎么查看?**是不是任何的c代碼編譯成lib和dll后都會有對應的.h頭文件,這個頭文件中就包含了類的方法和屬性信息?會不會存在沒有頭文件,但是我們可以正常使用lib和dll所提供的類?對于這樣的情況,那么如何知道該類要如何調用,并能否查看方法的doc?**因為是從Python過來學C++的,以前學過c,現(xiàn)在回來學發(fā)現(xiàn)C++相對python是有點不方便,或者說我不會用,因為在python中查看類的屬性方法和doc非常方便,一個dir函數(shù)就出來了:#導入pandas這個包importpandasaspd#pd.DataFrame是一個類,使用dir查看這個類中有的方法和屬性dir(pd.DataFrame)Out[3]:['T','_AXIS_ALIASES','_AXIS_IALIASES','_AXIS_LEN','_AXIS_NAMES','_AXIS_NUMBERS','_AXIS_ORDERS','_AXIS_REVERSED','_AXIS_SLICEMAP','__abs__','__add__','__and__','__array__','__array_wrap__','__bool__','__bytes__',...]#在ipython中查看doc,就是加個問號就知道怎么用了pd.DataFrame?Initsignature:pd.DataFrame(data=None,index=None,columns=None,dtype=None,copy=False)Docstring:Two-dimensionalsize-mutable,potentiallyheterogeneoustabulardatastructurewithlabeledaxes(rowsandcolumns).Arithmeticoperationsalignonbothrowandcolumnlabels.Canbethoughtofasadict-likecontainerforSeriesobjects.TheprimarypandasdatastructureParameters----------data:numpyndarray(structuredorhomogeneous),dict,orDataFrameDictcancontainSeries,arrays,constants,orlist-likeobjectsindex:Indexorarray-likeIndextouseforresultingframe.Willdefaulttonp.arange(n)ifnoindexinginformationpartofinputdataandnoindexprovidedcolumns:Indexorarray-likeColumnlabelstouseforresultingframe.Willdefaulttonp.arange(n)ifnocolumnlabelsareprovideddtype:dtype,defaultNoneDatatypetoforce.Onlyasingledtypeisallowed.IfNone,infercopy:boolean,defaultFalseCopydatafrominputs.OnlyaffectsDataFrame/2dndarrayinputExamples--------ConstructingDataFramefromadictionary.>>>d={'col1':[1,2],'col2':[3,4]}>>>df=pd.DataFrame(data=d)>>>dfcol1col2013124Noticethattheinferreddtypeisint64.>>>df.dtypescol1int64col2int64dtype:objectToenforceasingledtype:>>>df=pd.DataFrame(data=d,dtype=np.int8)>>>df.dtypescol1int8---Returntocontinue,qtoquit---#使用type查看類型In[5]:type(pd.DataFrame)Out[5]:typeIn[6]:type(pd)Out[6]:module那么c++中有沒有類似的方法,或者說要是有這些需求要如何處理?還是我理解錯了,只要能用都有.h文件的?謝謝
C++ 如何獲取類的屬性和方法?
溫溫醬
2019-05-23 11:40:22