Example :
#include %26lt;iostream%26gt;
#include %26lt;stdlib.h%26gt;
#include %26lt;string.h%26gt;
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;
}
In C++ , is it possible to pass a var as a argument ?
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%26lt;%26lt;pChar%26lt;%26lt;endl;
}
Reply:Yes, it is possible to pass a variable by reference.
Your method should be declared as:
int func(string%26amp; arg);
PS. Your example has many errors.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment