Post: Can someone verify this statement
02-18-2013, 01:48 AM #1
|C++|
< ^ > < ^ >
(adsbygoogle = window.adsbygoogle || []).push({}); in c++ the reason for making a function type pointer like this is so that we can initialize the return value to a pointer type. And if it was a reference "&" instead of pointer type we would be initializing the return value to reference type.

    int main(){int *gg=Function();.............}

[B][I][U]int *Function()[/U][/I][/B]
{
int x=3;
int *pointer=x;
return *pointer;
}


(im talking about the "int *Function()" part)

im just trying to solidify my understanding.
(adsbygoogle = window.adsbygoogle || []).push({});
02-18-2013, 09:58 PM #2
Originally posted by SLiiTH3R View Post
in c++ the reason for making a function type pointer like this is so that we can initialize the return value to a pointer type. And if it was a reference "&" instead of pointer type we would be initializing the return value to reference type.

    int main(){int *gg=Function();.............}

[B][I][U]int *Function()[/U][/I][/B]
{
int x=3;
int *pointer=x;
return *pointer;
}


(im talking about the "int *Function()" part)

im just trying to solidify my understanding.



How can you express the pointer from int to int*..? That would need a conversion of a different dimension if I'm not wrong.

Compile:
    
invalid conversion from 'int' to 'int*'
02-19-2013, 09:53 PM #3
|C++|
< ^ > < ^ >
Originally posted by LEzStarz View Post
How can you express the pointer from int to int*..? That would need a conversion of a different dimension if I'm not wrong.

Compile:
    
invalid conversion from 'int' to 'int*'


actually it was supposed to be a pointer *gg which is then set to gg=whatever()
where as 'int *soldier::setAmmo()' returns an address of a variable. Which does compile. This is why i really didnt need someone to compile the code for me, i could have done that mself. I wanted to know the reasoning behind the int * name part of the code.

pro tip:Microsoft word will never tell you why you spell somehting wrong. Neither will your compiler.(Even though the code i wrote on my compiler was'nt wrong, just saying)
02-20-2013, 05:56 AM #4
I'm assuming you mean.

    
int *gg Function()
{
return *item;
}


because:

int *function() doesnt have a return variable for the type.. if you're trying to pass data to an arguement then you can do so by the following..

    
int main()
{
int a = 2;
function( a );
cout<<a<<endl;
cin.get();
return 0;
}

function( int &n )
{
return (n + 3);
}


idk what you're trying to do though. so I hope this helped in some way lol.
02-24-2013, 05:48 AM #5
|C++|
< ^ > < ^ >
Originally posted by Jakes625PS3 View Post
I'm assuming you mean.

    
int *gg Function()
{
return *item;
}


because:

int *function() doesnt have a return variable for the type.. if you're trying to pass data to an arguement then you can do so by the following..

    
int main()
{
int a = 2;
function( a );
cout<<a<<endl;
cin.get();
return 0;
}

function( int &n )
{
return (n + 3);
}


idk what you're trying to do though. so I hope this helped in some way lol.


nvm i found out a while ago that all it means is that you are return ing a pointer type/ref. simple
02-24-2013, 06:40 AM #6
Originally posted by SLiiTH3R View Post
nvm i found out a while ago that all it means is that you are return ing a pointer type/ref. simple


ah okay. Glad you figured it out :p
02-24-2013, 07:13 PM #7
|C++|
< ^ > < ^ >
Originally posted by Jakes625PS3 View Post
ah okay. Glad you figured it out :p


can you help me? i want to know where i can pratice operator overloading.
02-24-2013, 09:35 PM #8
Originally posted by SLiiTH3R View Post
can you help me? i want to know where i can pratice operator overloading.


tbh, I don't even know what that is myself. well at least the term anyway.
02-27-2013, 12:13 AM #9
|C++|
< ^ > < ^ >
Originally posted by Jakes625PS3 View Post
tbh, I don't even know what that is myself. well at least the term anyway.


so your in the process of learning c++ too? In that case we should collab and talk to eachother more, i hear its good to have a friend who is also learning c++ at around the same level as you. It provides motivation and you can help eachother in the learning process.
02-27-2013, 01:55 AM #10
Originally posted by C
so your in the process of learning c++ too? In that case we should collab and talk to eachother more, i hear its good to have a friend who is also learning c++ at around the same level as you. It provides motivation and you can help eachother in the learning process.


If you want. lol.

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo