Connecting Tech Pros Worldwide Help | Site Map

C++ helppppp

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 19th, 2005, 06:47 PM
cajmoney
Guest
 
Posts: n/a
Default C++ helppppp

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.

  #2  
Old July 19th, 2005, 06:47 PM
WW
Guest
 
Posts: n/a
Default 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


  #3  
Old July 19th, 2005, 06:47 PM
Jerry Coffin
Guest
 
Posts: n/a
Default 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.
  #4  
Old July 19th, 2005, 06:47 PM
Mike Wahler
Guest
 
Posts: n/a
Default 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


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.