calling a method in a composite class .

This is a discussion on calling a method in a composite class . within the C++ Programming forums, part of the General Programming Boards category; I have a class A that has a private member variable ab.I also have a method that works with my ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    118

    calling a method in a composite class .

    I have a class A that has a private member variable ab.I also have a method that works with my variable ab.I have another class b that has class A a as a member variable(composition).I have discovered that if i try to call a method from class a it does not work.e.g this.a.getME().I am from a java background and it would work perfectly in java

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    That sounds weird ... did you make the getME() function public in A?
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    118
    Quote Originally Posted by oogabooga View Post
    That sounds weird ... did you make the getME() function public in A?
    yup i did.The answer i kept getting was out of scope

  4. #4
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Did you #include the header file for class A? (I think that's different from Java.)
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  5. #5
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    this.a.getME()
    'this' is a pointer in C++, use the '->' operator.
    Consider this post signed

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,179
    And if that does not work, then show us some code.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calling the overriden method from the base class
    By DavidP in forum C# Programming
    Replies: 2
    Last Post: 02-19-2010, 01:55 PM
  2. calling a class method within different class method
    By alyeska in forum C++ Programming
    Replies: 5
    Last Post: 03-08-2009, 10:56 AM
  3. calling a method from another file
    By Beowolf in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2007, 09:40 PM
  4. Problem calling external method from within a shared library
    By Major Tom in forum C++ Programming
    Replies: 0
    Last Post: 04-21-2007, 09:14 AM
  5. Calling a Method from Another Class...
    By Dan17 in forum C++ Programming
    Replies: 2
    Last Post: 02-02-2006, 05:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21