473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Difference between struct and class in c++ and c

Hi,

Part of the question could be OT, so please bare with me for that.
As I was told/know/read the main difference between struct and class is
that for a struct all member variables and methods are public.

I managed to write a small program as shown below, and managed to
successfully compile using c++ compiler but did not manage to do the
same with c compiler....

struct A
{
public:
A(){ printf(" A:: constructor \n"); }
~A(){ printf(" A:: destructor \n"); }
void print(){ printf(" A::print \n"); }
};
Does that mean what ever I had learned is pertaining only to C++ and
not C.

Thanks

Sep 7 '05 #1
3 6805
I managed to find the reply from an earlier posting by some body else,
so please ignore my posting.
I should have checked earlier postings before asking a question around
here....

Any how the answer is..
"In reality, there is little difference between a C struct and a
C++ class, at least when it comes to implementation. The main
difference
is that C++ supports (not requires, supports) object-oriented design
techniques
and so makes it a lot easier to code an object-oriented design than in
C"

Sep 7 '05 #2

Robben schreef:
Hi,

Part of the question could be OT, so please bare with me for that.
As I was told/know/read the main difference between struct and class is
that for a struct all member variables and methods are public.

I managed to write a small program as shown below, and managed to
successfully compile using c++ compiler but did not manage to do the
same with c compiler....

struct A
{
public:
A(){ printf(" A:: constructor \n"); }
~A(){ printf(" A:: destructor \n"); }
void print(){ printf(" A::print \n"); }
};
Does that mean what ever I had learned is pertaining only to C++ and
not C.


Yep. Constructors, destructors, the keywords class,public,protected and
private are all new in C++. These are needed to make C++ an OO
language.
That's not a goal of C.

You should avoid mixing the languages, certainly until you're more
familiar with both.

HTH,
Michiel Salters

Sep 7 '05 #3
Same with virtual ....
You opions must be from the fact that there in C++ is no difference
between

struct A
{

}
and
class A
{
public:

}

Sep 7 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Shea Martin | last post by:
I have been programming in C++ for over 4 years. I *think* I knew that a struct could have a constructor but I decided to dig into it a little more today, and found that there is very little...
22
by: Ook | last post by:
We have had a discussion on the differences between a class and a structure, and no one is in agreement. As I understand it, a structure defaults to public, a class defaults to private. There are...
6
by: XiongBin | last post by:
anybody who tell me: what is the difference between "struct" and "class"? :-)
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...
5
by: Chris | last post by:
Hi, I don't get the difference between a struct and a class ! ok, I know that a struct is a value type, the other a reference type, I understand the technical differences between both, but...
5
by: Martin Jørgensen | last post by:
Hi, Consider this code: --- beginning of code --- #include <iostream> using namespace std; class Child{ public:
7
by: raghunandan_1081 | last post by:
Hi guys, can you please tell me what is the Difference between c structure and c++ structure
5
by: Mack | last post by:
Hi, I want to ask what is basically main difference between struct and class?? when we should use struct instead of class.?? Mack.
6
by: fcvcnet | last post by:
Hi, I read the book C++ Primer, Fourth Edition By Stanley B. Lippman, Jos¨¦e Lajoie, Barbara E. Moo "If we define a class using the class keyword, then any members defined before the first...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.