You are here:

C++/class and struct2


i have found that struct can access specifiers...
is it correct the code....

// Similarity of struct and class

struct A {
 int i, j, k;
 int f();
 void g();

int A::f() {
 return i + j + k;

void A::g() {
 i = j = k = 0;

// Identical results are produced with:

class B {
 int i, j, k;
 int f();
 void g();

int B::f() {
 return i + j + k;

void B::g() {
 i = j = k = 0;

int main() {
 A a;
 B b;
 a.f(); a.g();
 b.f(); b.g();
} ///:~

I didn't have much time to look at the code and run
it but seems to be, there are some fatal flaws in this
program. First let me clarify some concepts, ofcourse
Structs can provide the same functionality as Classes
and they can also use specifiers, but, that method is
now obselete, and positively classes are used in a OOP
way, strucutres give programs a structured and lengthy

As far as codes are concerned, i see that, at the second
program there is construtor defined, though it will work
fine, but the program isn't in the consistent state. I
hope you know understand the concept of consistent state.
If any queries, please do reply me back, i will try to help.
What is your name?



All Answers

Answers by Expert:

Ask Experts




I can answer any question about functions,pointers,structures,object oriented programming basics of classes and data structures.My strong field is structured programming.


I have got 2 years experiece under C . I am able to answer about the structured concepts pointers to a little extent,OOP concepts. I have also experience in data Strucutres like Linked List, Stacks , Queues, Heaps, B Trees, Red Black Trees. I will try to satisfy with my knowledge. I am the Student of an expert here Martin, what i have learnt today, i just owe my every knowledge to him. He is the greatest.

©2016 All rights reserved.