By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,679 Members | 1,030 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,679 IT Pros & Developers. It's quick & easy.

are objs of classes and structs refrence types??

P: n/a
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

Dec 31 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On 2006-12-31 13:35, giddy wrote:
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.

--
Erik Wikström
Dec 31 '06 #2

P: n/a
giddy wrote:
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.
Dec 31 '06 #3

P: n/a
?- C++ ?? ?? ????? ?? ??????? new ??? ?? ?????? ???? ??? reference types, ??
???? ??, ??? ???? ????? ????????? ?? ?-stack ?? ??? new ??? ?? ?-heap

???? ????!

I know I can't use this language, so please forgive me
"giddy" <gi*******@gmail.comwrote in message
news:11**********************@i12g2000cwa.googlegr oups.com...
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


Dec 31 '06 #4

P: n/a
Mari wrote:
?- 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.

--
Clark S. Cox III
cl*******@gmail.com
Jan 1 '07 #5

P: n/a
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

Jan 1 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.