Solved

Shariing Public Class functions

Posted on 2003-11-02
2
244 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 125 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ get user from AD  (VS6) 7 114
VS2015 compilation and missing DLLs 9 193
C++ standard library based binary archive format 6 112
How can i compile this github project?? 2 105
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

710 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