Thread: Classes

  1. #16
    Registered User
    Join Date
    Apr 2003
    Ohhh I don't know about that. Ever heard of a "struct hierarchy"? Neither have I... structures don't facilitate object oriented concepts like inheritance and polymorphism like classes do.
    Well, I have to admit I've never tried using a "struct hierarchy" in C++, but if the following code works, then in C++ there's no difference between classes and structs accept for the default access:
    include <iostream>
    using namespace std;
    struct StructA
    	int a_number;
    	StructA(int num): a_number(num){};
    	int Get_a()
    		return a_number;
    	virtual void print()
    		cout<<"This is a."<<endl;
    struct StructB: public StructA
    	double b_number;
    	StructB(double num1, int num2 ): StructA(num2)
    		b_number = num1;
    	double Get_b()
    		return b_number;
    	virtual void print()
    		cout<<"This is b."<<endl;
    int main()
    	StructB my_b(5.1, 1);
    	StructA my_a(10);
    	StructA* pStructA = &my_a;
    	pStructA = &my_b;
    	return 0;
    Last edited by 7stud; 05-03-2003 at 03:53 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 10:47 AM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 08:04 AM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. Exporting VC++ classes for use with VB
    By Helix in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2003, 04:38 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM