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 5 1627
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
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.
?- C++ ?? ?? ????? ?? ??????? new ??? ?? ?????? ???? ??? reference types, ??
???? ??, ??? ???? ????? ????????? ?? ?-stack ?? ??? new ??? ?? ?-heap
???? ????!
I know I can't use this language, so please forgive me
"giddy" <gi*******@gmai l.comwrote in message
news:11******** **************@ i12g2000cwa.goo glegroups.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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
structures in C are the same as classes in another language such as C++
or Java only missing the ability to make the data private.
I've never had this explained sufficiently and would appreciate a good
answer. It doesn't need to be Mickey Mouse,...
|
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 their head, do they?
Many thanks!
--
Best Regards,
|
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 class, how this is possible when it
is not allowed to derive a struct from a class? and System.Object is the
reference type provided by the .NET Framework then why structs are value
types? since the struct are derived from System.Object then they...
|
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
instantiate an array of structures; consider the following useless
code :
using System;
struct MyPointS
|
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 the actual structure itself.
Is this true of C# also?
| |
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 that, a structure definition that includes
function pointers only defines the function prototypes to be used with
them, but not the actual implementations, whereas in C++, member
functions cannot be changed *unless* virtual functions are used, or the
|
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 the change. I
know that Structures are value types, sit on the stack, and are
generally more efficient to manipulate than reference types (i.e.
Classes). Structures cannot use inheritance, the finalize method or
default constructors. Can anyone...
|
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 overhead (I
think). A Struct seems more appropriate. At least it is what I would
have used in other languages. But since a Struct *can* hold methods,
I wander if I am saving anything. If not, why use it?
|
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 functions for manipulating a Date. However, it
does not specify that those functions should be the only ones to depend
directly on Date ’s representation and the only ones to directly access
objects of class Date . This restriction
can be...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |