Connecting Tech Pros Worldwide Help | Site Map

C++ helppppp

cajmoney
Guest
 
Posts: n/a
#1: Jul 19 '05
Hello I am taking a class in advance C++ and I need some help. My
problem is when I construct a object class I have to use a non member
function to allow the user to enter their name and store that name in
a local array. I cannot figure out how to pass that array into my
object class so I can display it to the screen. I guess my question
is: how do you return arrays from a function? How do you pass that
array to a member function.
WW
Guest
 
Posts: n/a
#2: Jul 19 '05

re: C++ helppppp


cajmoney wrote:[color=blue]
> Hello I am taking a class in advance C++ and I need some help. My
> problem is when I construct a object class I have to use a non member
> function to allow the user to enter their name and store that name in
> a local array. I cannot figure out how to pass that array into my
> object class so I can display it to the screen.[/color]
[color=blue]
> I guess my question is: how do you return arrays from a function?[/color]

You cannot. But you can use std::string instead (since you talk about a
name).
[color=blue]
> How do you pass that array to a member function.[/color]

You cannot. When you pass an array it "decays" into a pointer to the first
element of the array.

Post code:
http://www.parashift.com/c++-faq-lit...t.html#faq-5.8

--
WW aka Attila


Jerry Coffin
Guest
 
Posts: n/a
#3: Jul 19 '05

re: C++ helppppp


In article <65d7444f.0310050436.9c8c06c@posting.google.com> ,
cajmoney@cs.com says...[color=blue]
> Hello I am taking a class in advance C++ and I need some help. My
> problem is when I construct a object class I have to use a non member
> function to allow the user to enter their name and store that name in
> a local array.[/color]

Why would you have to do that? First of all, you probably want to use a
string instead of an array. Second, the code to construct the object
_should_ normally be in the ctor.
[color=blue]
> I cannot figure out how to pass that array into my
> object class so I can display it to the screen.[/color]

You can't pass an array as a parameter directly. You can pass a pointer
to the beginning of an array, or you can pass a class/struct that
contains an array (though you'd generally prefer to pass a pointer or
reference to the latter).
[color=blue]
> I guess my question
> is: how do you return arrays from a function? How do you pass that
> array to a member function.[/color]

My question is: can you give a more complete description of what you're
trying to accomplish? It seems to me that you're asking us about a
detail that will probably disappear completely in a better design.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Mike Wahler
Guest
 
Posts: n/a
#4: Jul 19 '05

re: C++ helppppp



"cajmoney" <cajmoney@cs.com> wrote in message
news:65d7444f.0310050436.9c8c06c@posting.google.co m...[color=blue]
> Hello I am taking a class in advance C++ and I need some help. My
> problem is when I construct a object class I have to use a non member
> function to allow the user to enter their name and store that name in
> a local array. I cannot figure out how to pass that array into my
> object class so I can display it to the screen. I guess my question
> is: how do you return arrays from a function?[/color]

You can't. Pass a pointer to the array.
[color=blue]
>How do you pass that
> array to a member function.[/color]

Via a pointer.

BTW a class in C++ which an array instead of a container
is imo not "advanced" at all.

-Mike


Closed Thread