C++ helppppp

C

cajmoney

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.
 
W

WW

cajmoney said:
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?

You cannot. But you can use std::string instead (since you talk about a
name).
How do you pass that array to a member function.

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-lite/how-to-post.html#faq-5.8
 
J

Jerry Coffin

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.

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.
I cannot figure out how to pass that array into my
object class so I can display it to the screen.

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).
I guess my question
is: how do you return arrays from a function? How do you pass that
array to a member function.

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.
 
M

Mike Wahler

cajmoney said:
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?

You can't. Pass a pointer to the array.
How do you pass that
array to a member function.

Via a pointer.

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

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top