how can i pass my array object in function arguments by reference?
-
hi ! i need to pass array of objects in the function by reference. can any one help me ? i created the following class declaration. class TagE { string x, string y, int z, public : void foo(TagE & )//?:confused: :confused: what should i write here? }; int main() { TagE t[25]; // how can i pass t[25] as function argument foo(t);// what should i write here } :confused: can any guide me or send me test/demo/example link? Amit
I think it would be:
void foo(TagE (&the_array)[25]);
although it would be clearer with a typedef:
typedef TagE array_of_25_tage[25];
void foo(array_of_25_tage& the_array);--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?
-
I think it would be:
void foo(TagE (&the_array)[25]);
although it would be clearer with a typedef:
typedef TagE array_of_25_tage[25];
void foo(array_of_25_tage& the_array);--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?
-
I think it would be:
void foo(TagE (&the_array)[25]);
although it would be clearer with a typedef:
typedef TagE array_of_25_tage[25];
void foo(array_of_25_tage& the_array);--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?
i exactly definded you what i want . in my DRmClient.cpp file #include "TagEditor.h" //// for tageditor class. TagEditor _ProtectSet[MAX_PATH]; //global object //// now i had fill up the object run time and try to pass this object to one function below hr = pkg.EncodeMediaContent(wInFile,w_Output,hDlg,HOST,UserID,sINIT_PACKAGE_RESPONSE,COMMUNICATOR_SCRIPT_FILE_PATH,PORT,hList,
_ProtectSet[25]
); the above function call the follwoing function HRESULT Package::EncodeMediaContent(WCHAR *pszInFile, WCHAR *pszOutFile, HWND hwndParent, string Host,string UserID, string InitPackageRequest,string ScriptFile,INTERNET_PORT Port,HWND hList,TagEditor _ProtectSet[MAX_PATH]) { //where i again pass that last parameter in other function string sConfigureResponse = GenerateConfigurePackageRequest(UserID,Host,ScriptFile,Port,hwndParent,InitPackageRequest,w_KeyID,hList,_ProtectSet); } string Package::GenerateConfigurePackageRequest(std::string uid,std::string host, std::string scriptFile, INTERNET_PORT port, HWND hwndParent,string sInitPackagingResponse,WCHAR *w_KeyID,HWND hList,TagEditor _ProtectSet[]) { //and here i am using the original object members e.g. like string Title = ""; Title=_ProtectSet[0].title; // now got it!!. } } Amit -
i exactly definded you what i want . in my DRmClient.cpp file #include "TagEditor.h" //// for tageditor class. TagEditor _ProtectSet[MAX_PATH]; //global object //// now i had fill up the object run time and try to pass this object to one function below hr = pkg.EncodeMediaContent(wInFile,w_Output,hDlg,HOST,UserID,sINIT_PACKAGE_RESPONSE,COMMUNICATOR_SCRIPT_FILE_PATH,PORT,hList,
_ProtectSet[25]
); the above function call the follwoing function HRESULT Package::EncodeMediaContent(WCHAR *pszInFile, WCHAR *pszOutFile, HWND hwndParent, string Host,string UserID, string InitPackageRequest,string ScriptFile,INTERNET_PORT Port,HWND hList,TagEditor _ProtectSet[MAX_PATH]) { //where i again pass that last parameter in other function string sConfigureResponse = GenerateConfigurePackageRequest(UserID,Host,ScriptFile,Port,hwndParent,InitPackageRequest,w_KeyID,hList,_ProtectSet); } string Package::GenerateConfigurePackageRequest(std::string uid,std::string host, std::string scriptFile, INTERNET_PORT port, HWND hwndParent,string sInitPackagingResponse,WCHAR *w_KeyID,HWND hList,TagEditor _ProtectSet[]) { //and here i am using the original object members e.g. like string Title = ""; Title=_ProtectSet[0].title; // now got it!!. } } Amitamitmistry_petlad wrote:
hr = pkg.EncodeMediaContent(wInFile,w_Output,hDlg,HOST,UserID,sINIT_PACKAGE_RESPONSE,COMMUNICATOR_SCRIPT_FILE_PATH,PORT,hList,_ProtectSet[25]);
why _ProtectSet[25]? Passing like this means you are passing only the 25th element of the array. Why dont you pass like
hr = pkg.EncodeMediaContent(wInFile,w_Output,hDlg,HOST,UserID,sINIT_PACKAGE_RESPONSE,COMMUNICATOR_SCRIPT_FILE_PATH,PORT,hList,_ProtectSet );
nave
-
amitmistry_petlad wrote:
hr = pkg.EncodeMediaContent(wInFile,w_Output,hDlg,HOST,UserID,sINIT_PACKAGE_RESPONSE,COMMUNICATOR_SCRIPT_FILE_PATH,PORT,hList,_ProtectSet[25]);
why _ProtectSet[25]? Passing like this means you are passing only the 25th element of the array. Why dont you pass like
hr = pkg.EncodeMediaContent(wInFile,w_Output,hDlg,HOST,UserID,sINIT_PACKAGE_RESPONSE,COMMUNICATOR_SCRIPT_FILE_PATH,PORT,hList,_ProtectSet );
nave
ok fine suppose i will pass like that then i should write pointer at recever end is it ?. then how can i access the members. because i passing this array object through two function 1) EncodeMediaContent(......,last param) //here i should put pointer 2) GenerateConfigurePackageRequest(..., last param )//here i should pointer Both last param having the same. so now you can give me the guide line. i have take pointer at two place but let me know how can i got the objects value. e.g. Title=_ProtectSet[0].title; Amit
-
ok fine suppose i will pass like that then i should write pointer at recever end is it ?. then how can i access the members. because i passing this array object through two function 1) EncodeMediaContent(......,last param) //here i should put pointer 2) GenerateConfigurePackageRequest(..., last param )//here i should pointer Both last param having the same. so now you can give me the guide line. i have take pointer at two place but let me know how can i got the objects value. e.g. Title=_ProtectSet[0].title; Amit
amitmistry_petlad wrote:
- EncodeMediaContent(......,last param) //here i should put pointer 2) GenerateConfigurePackageRequest(..., last param )//here i should pointer
you dont need to change this parameters. The current definition is ok. And even though u recieve a pointer in the last function, you will be able to use like Title=_ProtectSet[0].title; Modify the code as I said and try compliling the code. It should compile with zero errors.And let me know if there is any error.
nave
-
amitmistry_petlad wrote:
- EncodeMediaContent(......,last param) //here i should put pointer 2) GenerateConfigurePackageRequest(..., last param )//here i should pointer
you dont need to change this parameters. The current definition is ok. And even though u recieve a pointer in the last function, you will be able to use like Title=_ProtectSet[0].title; Modify the code as I said and try compliling the code. It should compile with zero errors.And let me know if there is any error.
nave
ok done
-
Michael Dunn wrote:
void foo(TagE (&the_array)[25]);
is there any difference between the above and
void foo(TagE the_array[25]);
?nave
Consider the case where you assign a new value to
the_array
insidefoo()
. Whenthe_array
is a reference, the change is visible to the caller. (I'm not positive, this is an area of black-magick syntax that I rarely venture into)--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?
-
Consider the case where you assign a new value to
the_array
insidefoo()
. Whenthe_array
is a reference, the change is visible to the caller. (I'm not positive, this is an area of black-magick syntax that I rarely venture into)--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?
-
TagE the_array[20];
void foo(TagE the_array[25]);?
foo(the_array); //OKIn this case, you can pass a pointer to the function.
TagE the_array[20];
void foo(TagE (&the_array)[25]);foo(the_array); //Error
But in this case, you should pass a correct arrary to the function(
TagE the_array[25];
).