Struct or class?

R

Rolf Magnus

George2 said:
Hello everyone,


Multiplies is a struct, why MSDN said it is a class?

I don't know why it does. I guess you'd have to ask the author.
Anyway, in C++, a struct and a class are basically the same thing.
 
R

Rolf Magnus

George2 said:
Hello everyone,


Multiplies is a struct, why MSDN said it is a class?

I don't know why it does. I guess you'd have to ask the author.
Anyway, in C++, a struct and a class are basically the same thing. But
actually, multiplies is neither a struct nor a class. It's a template.
 
C

C++

There is only one difference between classe and strucure.
Defaut view for classes is private and for structures it's public
 
M

matfarell

There is only one difference between classe and strucure.
Defaut view for classes is private and for structures it's public

Well, that's true. But then what was the need of introducing a class
when a struct was already there? I mean that when C++ was designed,
Stroustrup may have thought of it. But "as a beginner" i still wonder
why a class was incorporated , even though struct was already there
"doing the work".
 
A

Alan Woodland

Well, that's true. But then what was the need of introducing a class
when a struct was already there? I mean that when C++ was designed,
Stroustrup may have thought of it. But "as a beginner" i still wonder
why a class was incorporated , even though struct was already there
"doing the work".
I'd guess the idea was that by making the default access modifier
private it would encourage information hiding and encapsulation. Of
course to maintain backwards compatibility with C you can't just change
the default with structs, otherwise everything would break, hence the
need for a new keyword. Additionally I'd argue that it serves to
encourage developers moving from C to C++ to think about things in a
different frame of mind and to use the new features of the OO paradigm
that C++ makes available.

That's just my view though, and I'm sure someone out there has more
historical knowledge on this one..

Alan
 
H

Howard

C++ said:
There is only one difference between classe and strucure.
Defaut view for classes is private and for structures it's public

By "default view" I assume you meant default visibility of its members.
Also, default inheritance for struct is public, and private for class.
-Howard
 
H

Howard

Well, that's true. But then what was the need of introducing a class
when a struct was already there? I mean that when C++ was designed,
Stroustrup may have thought of it. But "as a beginner" i still wonder
why a class was incorporated , even though struct was already there
"doing the work".

My first C++ compiler (Turbo C++) defined class and struct differently. A
struct was a normal C struct, what we now call POD. You had to use the
"class" keyword in order to be able to add member functions and make use of
inheritance and polymorphism. Later, the C++ standard was developed which
defined struct and class as the same except for the public/private issues.

Many programmers still use structs only for PODs, and classes for everything
else.

-Howard
 
T

terminator

Well, that's true. But then what was the need of introducing a class
when a struct was already there? I mean that when C++ was designed,
Stroustrup may have thought of it. But "as a beginner" i still wonder
why a class was incorporated , even though struct was already there
"doing the work".

I think they were not certian about future and thought that semantics
of class were about to change .

regards,
FM.
 
T

terminator

My first C++ compiler (Turbo C++) defined class and struct differently. A
struct was a normal C struct, what we now call POD. You had to use the
"class" keyword in order to be able to add member functions and make use of
inheritance and polymorphism. Later, the C++ standard was developed which
defined struct and class as the same except for the public/private issues.

Many programmers still use structs only for PODs, and classes for everything
else.

Many just dont.
VC++ STL is completely defined via structures.

regards,
FM.
 
J

James Kanze

Multiplies is a struct, why MSDN said it is a class?

Because it is a class. There are no structs in C++.

There are two different keywords which can be used to define a
class: struct and class. Conventions concerning their use vary:
some people limit struct to pure POD's, others use it anytime
all members are public, and still others (like myself) if all
data members are public. In the latter case, some will use
struct if there are no data members, others will use class (and
others, like myself, are somewhat inconsistent). Regardless of
the keyword used, however, what is defined is a class.
 

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

Similar Threads

safearray 2
struct inside a class 0
MSDN volatile sample 13
manifest file 2
Structured exception 1
template<class Type> struct iterator_traits<const Type*> 0
Performance counter index 2
entry point of application 22

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top