Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Shariing Public Class functions

Posted on 2003-11-02
2
Medium Priority
?
247 Views
Last Modified: 2010-04-01
Hello,  Im new to c++, so....  

I have 2 headerfiles, one class in each, with various public functions (Accesors etc..)  The functions corresponding with each header file are defined in thier own seperate .cpp files.  And there is a main of course.  So thats five files..  

I believe what I am trying to do is aggregation, I want to access a private value from one object to be used in a method from the other object.   So what I assumed would work is calling the public accessor method from the class that I want to retrieve the value from.  But...  I am getting the following compilation error

In function 'void feed()'
'getAttributes" undeclared (first use this function)

I have each seperate header included. so that cant be the problem.  I know the problem is when I try and call that function its not aware of its existance because I am calling it from inside another class..  My question:  Is there any way that I can allow one class to retrieve a private variable from another using the public accessor method from the class where the private value resides?

Many Thanks,
DJ.
0
Comment
Question by:DMJohns
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
bcladd earned 500 total points
ID: 9666554
(1) Class A has two files:
     classA.h
     classA.cpp

Class B has two files:
    classB.h
    classB.cpp

In Class B you want to access a member function of class A? It looks from the error that you don't use a variable of type B in the function inside class A. That is getAttributes cannot be called without a pointer, reference or object of type B:

    B sometB;
    someB.getAttributes(); // this should be fine.

-bcl
0
 
LVL 6

Expert Comment

by:durgaprasad_j
ID: 9666651
Try using 'friend' functions , so that u can access one function in other class .

Thanks
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question