are objs of classes and structs refrence types??

G

giddy

hi ,

i'm a C / C# programmer .. have'nt done C++,

in C# .. . object instances of classes ( TextBox txt = new TextBox();)
are reference types. Structs on the other hand are value types.

In C++ i knw there are a few difference between classes and structs but
i need to know if there are value or refrence types.

Thanz

Gideon
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

hi ,

i'm a C / C# programmer .. have'nt done C++,

in C# .. . object instances of classes ( TextBox txt = new TextBox();)
are reference types. Structs on the other hand are value types.

In C++ i knw there are a few difference between classes and structs but
i need to know if there are value or refrence types.

They are what you want them to be, you can have them as value, reference
and pointer. What you use will depend on the situation.

The following is a short demonstration:

class Test
{
int a;
public:
Test() : a(0) { }
};

int main()
{
// Create as value (on stack), notice no ()
Test test1;

// test2 is a reference to test1, notice the &
Test& test2 = test1;

// Create an instance of Test on the heap and make
// test3 a pointer to that instance
Test* test3 = new Test();

// Make test4 a reference to test3
Test& test4 = *test3;

}

I'd advice you to find a good book and read up on the differences and
usages of the different types. As an example it's often a good idea to
pass classes/structs as referencest to functions:

int foo(Test& t)
{
// Do something
}

If possible avoid using pointers, but as you'll discover it's not always
possible.

The difference between class and struct is that by default a member of a
struct is public but a member of a class is private.
 
J

Jacek Dziedzic

giddy said:
hi ,

i'm a C / C# programmer .. have'nt done C++,

in C# .. . object instances of classes ( TextBox txt = new TextBox();)
are reference types. Structs on the other hand are value types.

In C++ i knw there are a few difference between classes and structs but
i need to know if there are value or refrence types.

By default, value types. Whenever you want a reference, you
need to explicitly tell the compiler using the '&' symbol.

The only difference between a class and a struct is the one
Erik already told you.

HTH,
- J.
 
M

Mari

?- C++ ?? ?? ????? ?? ??????? new ??? ?? ?????? ???? ??? reference types, ??
???? ??, ??? ???? ????? ????????? ?? ?-stack ?? ??? new ??? ?? ?-heap

???? ????!

I know I can't use this language, so please forgive me
 
C

Clark S. Cox III

Mari said:
?- C++ ?? ?? ????? ?? ??????? new ??? ?? ?????? ???? ??? reference types, ??
???? ??, ??? ???? ????? ????????? ?? ?-stack ?? ??? new ??? ?? ?-heap

???? ????!

I know I can't use this language, so please forgive me

Whatever language you were trying to post in; it didn't work.
 
G

giddy

hey ,

thanks Erik , its going to be a while now before i learn C++ ,
personally i LOVE C# and im gonna get grounded in it first. (i know C ,
Vb and i've done a bunch of other languages too =) ) I just wanted to
know a little bit ABOUT C++.


Jakek wrote :By default, value types.

Yep , this is exactly what i wanted.I should have specified BY DEFAULT.

Thanks

Gideon
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top