English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Example :

#include
#include
#include
using namespace std;

class test
{
private:
public:
int func(pass_string){

pass_string = " Hello " ;

} };






int main()
{
test test1;

string pass_string


test1.func(pass_string);




system("pause")
return 0;
}

2007-01-09 07:45:03 · 2 answers · asked by chaessigbikerboy 2 in Computers & Internet Programming & Design

2 answers

you cant pass the string "hello" as an argument, BUT you can pass a pointer to the string, which contains "hello".

char pass_string[] = "Hello"; //or could be CString type
int func(char *pChar);

int main()
{
func(pass_string);
}

func(char* pChar)
{
cout< }

2007-01-10 01:28:46 · answer #1 · answered by justme 7 · 0 0

Yes, it is possible to pass a variable by reference.
Your method should be declared as:
int func(string& arg);
PS. Your example has many errors.

2007-01-09 07:57:45 · answer #2 · answered by gtopala 4 · 1 1

fedest.com, questions and answers