Can someone please tell me the difference between Class and Structure in C++ ???
I cant find any..!!
Thanks

Recommended Answers

All 4 Replies

What is the "default access specifier" for each?

I think that in Class you can define functions and other variables
But in structure you only can define normal variables like int or float or even other struct variable

I agree to the default access specifier....
It's public for structure and private for class....
But as far as functions are concerned, i can create them in structure too...
Is that the only diff... access specifier ???
Thanks

No, you can have functions in a struct (when speaking of the C++ variety -- C structs can only have function pointers). The only difference between structs and classes is the default access specifier.

class MyClass
{
     int a;
}; 

struct MyStruct
{
     int a;
};

In each case is "a" public, private, or protected?
For class, the default is private. For struct, the default is public.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.