View Full Version : C++ function references
optimism_
05-08-2003, 01:08 AM
hi
i have the following code
function doSummit(char* string, char& names[MAX_PAIRS][MAX_NAME], char& values[MAX_PAIRS][MAX_NAME], int& pairs){
//so some stuff here that modifies the args
}
int main(){
int pairs = 0;
char names[MAX_PAIRS][MAX_NAME] = {0};
char vars[MAX_PAIRS][MAX_VALUE] = {0};
doSummit("this is my string", names, vars, pairs);
return 0;
}
however, there is always a compiler error "Cannot convert `char" on the line of the function call. Am i missing something here about passing multidimensional arrays of chars by reference or is it something trivial. Please help
optimism_
BloodXero
05-09-2003, 04:40 PM
in my experiences "function" is not a valid data type. thats in javascript and java but not c++. all functions in c++ must have a data type (either predefined or user created by a class/struct).
optimism_
05-09-2003, 06:13 PM
oh yeah! :o
in the actual c++ file it is int and returns 0;
When i wrote the post i simplified the function a lot, and i have been doing a lot of php stuff recently. Still, it was a STUPID mistake to make !
BloodXero
05-09-2003, 07:46 PM
ok why would you pass the address of the char parameter instead of a pointer? is there some reason for this?
but anyways i believe the problem might be that in the function the parameter isnt designated as an array, just a single char. you might want to try setting it to char* string[]. or you could #include <string> and do it string* (variable name) and pass in that same thing. but im not totally sure what is causing it but im prety sure it might be the single char* string. also you probably might want to change the variable name from string to something else because if you are including <string> already then it might interfere as a keyword.
[edit]another thing is that the multidimensional char array MIGHT do something but i doubt it. id just check on it.
optimism_
05-09-2003, 08:42 PM
As i said, this function is very much simplified, and i only included the prototype. The actual string variable is char* qstring. I see i must have made it confising, so ill dump the entire routine. The reason im using references is because the c++ book ive got outlines by-value, by-address, and by-reference, and claims that the & reference operator is a shortcut to using pointers.
code from book:
void fn(int& intArg){
intArg = 10;
}
void parent(void){
int n = 0;
fn(n)
//here the vlue of n is 10;
}
now my actual function prototype and calling code
//prototype
int query(char* qstring, char* pName[], char* pValue[], int* pairs);
//calling code
int pairs = 0;
char names[MAX_PAIRS][MAX_NAME] = {0};
char vars[MAX_PAIRS][MAX_VALUE] = {0};
query("name=optimism_&email=optimism_@hotmail.com&name=value", &names, &vars, &pairs);
BloodXero
05-09-2003, 11:59 PM
from that i really cant help you man. im sorry i couldnt do anything for you. try www.experts-exchange.com if no one can help you here. its really big and cool but you have limited question points or you have to buy them which is really stupid.
optimism_
05-10-2003, 02:30 PM
thx anyway
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.