c++ - I'd like to know where to declare variables, according to philosophy of programmers -


i student studying mfc.

i want declare childview region variables.

where have declare variables? header file? or cpp file?

i think both work well. want know general style.

please let me know desirable.

// childview.h : interface of cchildview class     //  #pragma once // cchildview window class cchildview : public cwnd { // construction public:     cchildview(); ... ... // user variables public:     cfile* pimgfile = null;     ulonglong imglength, framelength;     unsigned char rrr[288][352];     unsigned char ggg[288][352];     unsigned char bbb[288][352];      unsigned char yyy[288][352];     unsigned char uuu[144][176];     unsigned char vvv[144][176]; }; 

or

// childview.cpp : implementation of cchildview class // #include "stdafx.h" #include "doyup_yuv_hw7-8.h" #include "childview.h"  #ifdef _debug #define new debug_new #endif   // cchildview  cchildview::cchildview() {     cfile* pimgfile = null;     ulonglong imglength, framelength;     unsigned char rrr[288][352];     unsigned char ggg[288][352];     unsigned char bbb[288][352];      unsigned char yyy[288][352];     unsigned char uuu[144][176];     unsigned char vvv[144][176]; } 

in addition, wondered define statements located.

after (3)#pragma once in header file?

or after (9)#endif in cpp file?

where have declare variables? header file? or cpp file?

here have specify declaration , implementation not tied respectively header file , cpp file. it's thing have them separated in header file , cpp file not restrictively necesary.

variable scope

in example variables declared in "header file" declared inside class, members of class, , can use them objects of class, variables declared in cpp file declared inside constructur available in method , cannot used anywhere else

where use defines?

that scope, define in header file can used in other files include it, defined when compiler gets point, if have file compiled before, not contain define. might want @ preprocessor definitions too. might want set defines in "stdafx.h" file. in case doesn't seem need define because anyway can use _debug declared automaticaly.


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -