DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2006
    Posts
    14

    About Classes and Member functions

    Hi All;
    I have two classes;
    first class,
    Code:
    class  A
    {
    //
    Public:
    void read_data1(fstream&);
    void write_data1(fstream&);
    };
    
    A::read_data1(fstream & in)
    {
    //reading data "here i use vector to store data"
    }
    
    B::write_data(fstream& out)
    {
    //writing data
    }
    second class,
    Code:
    class  B
    {
    //
    void get_result(fstream &);
    void out_result(fstream &);
    }
    Now my problem is, I want use the first class member function into second class member function as following,
    Code:
    B::get_result(fstream & in)
    {
    //.......reading data(directly use class A member funtion here)
    }
    
    B::out_result(fstream & out)
    {
    //.......writing data (directly use class A member function here)
    }
    Please tell me how can I do this?

    Thanks in advance!

    Rgds,
    Sitha

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    This is possible only if B has a member object of type A, and you call the member function of A through that object.

    I think you should reconsider the design. If B's functions need to call A functions, maybe they should be base and derived classes or something that expresses the relationship between these two classes.
    Danny Kalev

Similar Threads

  1. Replies: 26
    Last Post: 12-01-2012, 04:12 AM
  2. Need help with classes lab
    By Luvanime in forum C++
    Replies: 8
    Last Post: 05-04-2007, 07:17 PM
  3. Replies: 1
    Last Post: 08-10-2006, 12:44 AM
  4. derived classes and virtual function
    By snuffalufagus in forum C++
    Replies: 4
    Last Post: 03-22-2005, 10:18 AM
  5. Collection classes revisited
    By Marco Antonio Pérez López in forum .NET
    Replies: 0
    Last Post: 06-09-2001, 10:22 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links