472,989 Members | 2,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

are objs of classes and structs refrence types??

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
5 1574
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
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
?- 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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: nick | last post by:
I have tried finding an answer to this, but most people just explain classes as a more modular way to program. It seems to me that (forgetting OO programming which I don't quite understand) the...
4
by: Christopher Ireland | last post by:
Hi -- I'm trying to find an example of a nested class implemented within the .NET Framework itself but without much success. I don't suppose that anybody knows of such an example off the top of...
10
by: Ashish Sheth | last post by:
Hi Gurus, In C# why struct can't be inherited from another struct, just like a class can be inherited from another class? another question is all struct by default are inherited from System.Object...
2
by: david | last post by:
Well, as a matter of fact I_HAD_MISSED a basic thing or two, anyway, although Ollie's answer makes perfectly sense when dealing with classes, it doesn't seem to me to apply as well if you have to...
11
by: Macca | last post by:
Hi, I'm writing an application that will pass a large amount of data between classes/functions. In C++ it was more efficient to send a pointer to the object, e.g structure rather than passing...
5
by: Bilgehan.Balban | last post by:
Hi, I am currently brushing up my c++ knowledge and I would like to ask you about the differences between classes and C structs, in the function/method perspective. 1) Is it correct to say...
2
by: thomasfarrow | last post by:
At work, our development team has a development standards document that insists Structures should never be used. I'm looking to change this standard but need a suitable argument in order to make...
29
by: Dom | last post by:
I'm really confused by the difference between a Struct and a Class? Sometimes, I want just a group of fields to go together. A Class without methods seems wrong, in that it carries too much...
19
by: desktop | last post by:
There is a lot of info on this topic on google. But in Bjarne Stroustrup 's book page 225 he writes: "The declaration of Date in the previous subsection (declared as a struct) provides a set of...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.