Reference to Class Member Functions

Hello all.
I have a question about references to LV class member functions. I have a small example to demonstrate my problem.
My test class Base implements a reentrant public dynamic dispatch member function, doSomething.vi. 
Another test class, Child, inherits Base and overrides the implementation of doSomething.vi.
Now say I have an array of Base objects (which could include any objects from classes that inherit Base). I want to run the doSomething methods for all the objects in the array in parallel.
In C++, I'd define a pointer to the virtual member function doSomething, and use it with each object in the array and the correct version of doSomething would be called.
In Labview, the only way I've found to do it is like this:
This is less than ideal, because it relies on every child class implementing doSomething, and relies on specific names for the inputs to the method. 
Is there a better way to do this?
Thank you,
Zola

I still suspect you are over-working this code and not leting LVOOP do tis thing.
As I understand it you want to creae an active object but detemine its class at run time. The recent Architect summit touched on messaging for what they are calling a "worker Pool" pattern or what-not. YOu may want to search on the summit stuff. lacking that I'll share some images of where I did something similar ( I think). Note this is an older app and new stuff like the "Start Asyncronous call..." has been introduced making this even easier.
I want to create a new Active Object (thread running in the background) so I invoke a method to do so
It invokes the following that create some queues for talking to it and getting info back.
Time does not permit me doing a complete write-up but I have assembled the above images into a LVOOP Albumn found here.
When you click on one of those images you will get a large view as shown in this example.
Just below that image you will find a link to the original thread where I posted the image and talked about it.
I believe the best I can do for you at the moment is to urge you to browse my albumn and chase the links.
That agllery was assembled in an attmept to help you and other before you asked. I hope it is helpful.
Ben 
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction

Similar Messages

  • Pass C++ Class Member Function as a callable function in AIR Native Extension

    I'm writing an ANE and I'd like to know if anyone has been able to pass a C++ class member function pointer as a callable function from AIR? I have tried this so far with a little bit of C++11 trickery and it's crashing. I've also statically linked the libstdc++ into my library, according to the documentation, in order to ensure that these features I use work correctly. I have code like so:
    FakeWorld* world = new FakeWorld();
    *numFunctions = 1;
    memberFunctions = (FRENamedFunction*) malloc(sizeof(FRENamedFunction) * (*numFunctions));
    ANEMemberFunction mCreateFakeBody = std::tr1::bind(&FakeWorld::createFakeBody, world, std::tr1::placeholders::_1, std::tr1::placeholders::_2, std::tr1::placeholders::_3, std::tr1::placeholders::_4);
    ANEFunction* createFakeBody = mCreateFakeBody.target<ANEFunction>();
    memberFunctions[0].name = (const uint8_t*) "createFakeBody";
    memberFunctions[0].functionData = NULL;
    memberFunctions[0].function = createFakeBody;
    FRESetContextNativeData(ctx, (void*)world);
    I just realized I'm using C here for allocating the member functions array.. silly me, but I don't think this is the cause of my issue. I refuse to believe that Adobe has built to the Native Extensions portion of the runtime in such a way that I have to cram every single function I want to create (natively) into a global, C formatted namespace (Especially since the documentation says that C is only required for the extenion and context initializing function interfacing and the rest of the code can be done in C++ or objective-C). So please let me know if and how this is possible and I thank you so much in advance for your time!P.
    P.S. Currently when I run this code, I can do the object initialization just fine. As soon as I invoke the "createFakeBody" method on the native side, the runtime dies and simply says:
    Problem signature:
      Problem Event Name: BEX
      Application Name: adl.exe
      Application Version: 3.1.0.4880
      Application Timestamp: 4eb7612e
      Fault Module Name: StackHash_0a9e
      Fault Module Version: 0.0.0.0
      Fault Module Timestamp: 00000000
      Exception Offset: 00000000
      Exception Code: c0000005
      Exception Data: 00000008
      OS Version: 6.1.7601.2.1.0.256.48
      Locale ID: 1033
      Additional Information 1: 0a9e
      Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
      Additional Information 3: 0a9e
      Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
    Read our privacy statement online:
      http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409
    If the online privacy statement is not available, please read our privacy statement offline:
      C:\Windows\system32\en-US\erofflps.txt
    Thanks again for your assitance.

    It's been a little while since i've dealt with C++ and not up to speed on tr1 or C++0x, so forgive me if i'm not helping.
    The the examples of std::tr1::bind that i'm seeing out there seem to be either dereferencing the bound 'this' pointer when creating the bound method, i.e. in your case *world instead of world, or using std::tr1::ref(*world), therefore i believe that bind expects the bound parameters to be passed by reference.
    Given that the result of std::tr1::bind is callable (basing that on http://stackoverflow.com/questions/3678884/virtual-member-functions-and-stdtr1function-how -does-this-work) could you simplify to the following:
    memberFunctions[0].name = (const uint8_t*) "createFakeBody";
    memberFunctions[0].functionData = NULL;
    memberFunctions[0].function = std::tr1::bind(&FakeWorld::createFakeBody, *world, std::tr1::placeholders::_1, std::tr1::placeholders::_2, std::tr1::placeholders::_3, std::tr1::placeholders::_4);
    Or for an even simpler starting point, creating a test member function 'helloWorld' in FakeWorld that takes no arguments and using:
    memberFunctions[0].name = (const uint8_t*) "helloWorld";
    memberFunctions[0].functionData = NULL;
    memberFunctions[0].function = std::tr1::bind(&FakeWorld::helloWorld, *world);
    Hope this helps.

  • Binding function pointer to class member fnction

    Hi,
    I have created a function pointer to class nonstatic member function. But facing some compilation issue. Can someone help on this.
    #include "stdafx.h"
    #include "iostream"
    #include <functional>
    using namespace std;
    using namespace std::placeholders;
    class A
    public:
    void Fun(void* param, bool b){cout<<"Hi\n";}
    typedef void (A::*fptr)(void*,bool);
    int _tmain(int argc, _TCHAR* argv[])
    fptr obj;
    auto f = std::bind(&A::Fun, &obj,_1,_2);
    f(NULL,1);
    return 0;

    See some samples about std::bind and std::function
    http://en.cppreference.com/w/cpp/utility/functional/bind
    http://en.cppreference.com/w/cpp/utility/functional/function
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Making all named member functions of an actionscript class avlbl to ExternalInterface automatically

    Making all named member functions of an actionscript class available to ExternalInterface automatically :
    I am trying to custom-tweak the as3 compiler to generate instructions to register all functions in the ClassDefinitionNode to ExternalInterface.
    I guess the operation will have to be performed somwhere between the analyze sequences of the compiler, but am not quite able locate where.
    I have this codelet (executed for all constructors, for every non-constructor)
                    ArgumentListNode argListNode = new ArgumentListNode(
                            new LiteralStringNode(
                                    NodeMagic.getClassName(clNode)+ "." + functionCommonNode.identifier.name), 0);
                    //argListNode.items.add(new LiteralNullNode());
                    argListNode.items.add(new IdentifierNode(functionCommonNode.identifier.name, 0));
                    MemberExpressionNode mnode = new MemberExpressionNode(new IdentifierNode("ExternalInterface", 0),
                            new InvokeNode("addCallback",
                                    argListNode),0);
                    mnode.ref = new ReferenceValue(cx, null, "ExternalInterface", ObjectValue.intrinsicNamespace); //NOT TOO SURE ABOUT THIS ONE
                    constructor.body.items.add(mnode
    Any assistance would be appreciated!
    Thanks!

    Making all named member functions of an actionscript class available to ExternalInterface automatically :
    I am trying to custom-tweak the as3 compiler to generate instructions to register all functions in the ClassDefinitionNode to ExternalInterface.
    I guess the operation will have to be performed somwhere between the analyze sequences of the compiler, but am not quite able locate where.
    I have this codelet (executed for all constructors, for every non-constructor)
                    ArgumentListNode argListNode = new ArgumentListNode(
                            new LiteralStringNode(
                                    NodeMagic.getClassName(clNode)+ "." + functionCommonNode.identifier.name), 0);
                    //argListNode.items.add(new LiteralNullNode());
                    argListNode.items.add(new IdentifierNode(functionCommonNode.identifier.name, 0));
                    MemberExpressionNode mnode = new MemberExpressionNode(new IdentifierNode("ExternalInterface", 0),
                            new InvokeNode("addCallback",
                                    argListNode),0);
                    mnode.ref = new ReferenceValue(cx, null, "ExternalInterface", ObjectValue.intrinsicNamespace); //NOT TOO SURE ABOUT THIS ONE
                    constructor.body.items.add(mnode
    Any assistance would be appreciated!
    Thanks!

  • Problem with reference and class

    I would like to transit a Data object in member function of another class with Labview 9.0 reference with "In place element structure". I use the reference for optimize allocation memory.
    When i use a dispatch static : Vi is executable  -> "TestRefAppExt Statique.vi"
    With Dispatch dynamic : Vi is not executable (because Read/Write a reference's data value : class's Object in a reference can't be replaced by another) -> "TestRefAppExt DynamiqueWithoutParent.vi"/"TestRefAppExt DynamiqueWityParent.vi"
    When i use Preserve Run-Time Class function the Vi becomes executable
    but it creates some allocations. Labview creates copy of data object
    when i'm running the vi. (increase size of data you'll see)
    The problem is that i can't recuparate the same object without copy in dispatch dynamic. Because LabView can't change the data object transited in a dispatch dynamic function of another class (child class).
    I compared in project labview Execution's performance with and without Reference in dynamic and static and for compare, with Message Box and a Reference of Data object's cluster.
    Without reference, i made three Vi : "TestAppExt Statique.vi", "TestAppExt DynamiqueWithParent.vi" and  "TestAppExt DynamiqueWithoutParent.vi"
    The static's function works well, but when Labview calls dispacth Dynamic functions, it works more slowly.
    With reference, i made three vi too : "TestRefAppExt Statique.vi", "TestRefAppExt DynamiqueWithParent.vi" and "TestRefAppExt DynamiqueWithoutParent.vi" with cast Preserve Run-Time Class.
    All This functions are more slowly than without reference.
    I tried for fun to test with the same class with Message Box : "TestRefAppExt Fifo.vi" and Cluster "TestRefAppExt DynamiqueCluster.vi" with the dynamic function. The result is better than with reference in dynamic.
    "TestRefAppExt StatiqueRef.vi" and "TestRefAppExt DynamiqueRef.vi" are a solution of this problem but it's better to work with In place element structure. And it doesn't resolve reference performance in execution.
    Why it's not possible to recuperate data object after a dispatch dynamic?
    Why the performance is not good with LabView reference 2009?
     I attached the project.
     Could you help me please
    thank you so much.
    Pascal
    Attachments:
    RefTest.zip ‏476 KB

    Yes, it helps but there is one thing that isn't being replicated which is the possibility to remove the link from the generated editor.
    My EMF looks like:
    @gmf.node(label="uri", figure="ellipse", label.edit.pattern="{0}", label.view.pattern="<<Class>> {0}", label.icon="false")
    class Class extends Resource {
    @gmf.link(target="subClassOf", target.decoration="arrow", label.text="subClassOf", label.readOnly="true")
    ref Class[*] subClassOf;
    And when I do the fix with self.subClassOf.remove(self) the link isn't removed (although now the model now passes the validation). Is there any easy way to do that?
    Regards

  • [SOLVED] Passing a non-static member function as a function pointer

    I need to pass a function pointer to a public method to a system call, nftw() to be precise.
    I know that member functions don't match the required signature because of the hidden 'this' pointer, but
    the only way to work around that is by using a small wrapper function that makes use of a global variable (the object of which I want to call the method).
    Speaking in code, this is the way I've solved the problem currently:
    // create a global variable here
    static MyObject obj;
    static int myObject_method_wrapper(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf) {
    return obj.handleDirEntry(fpath, sb, tflag, ftwbuf);
    // somewhere in main()
    nftw(walkroot, myObject_method_wrapper, 20, FTW_PHYS);
    Now, my question: Can't this be done without a global instance of MyObject? It is pointed out here that other ways are existent, but sadly they are not mentioned.
    Glad if someone could help me out!
    Last edited by n0stradamus (2012-04-24 22:59:47)

    I think you are stuck:
    1. You are not in control of the interface (of nftw), and furthermore,
    2. You are not in control of any of the parameters sent to the callback.
    nftw has no idea which one of your objects it is supposed to reference, and
    there's no apparent way to tell it.
    But given this situation, are you sure it makes sense to use a non-static
    member?  It seems kind of strange to me-- any instance-specific data is
    necessarily going to be independent of the function calls!  So even if you
    engineer something to avoid using a global, whatever you engineer is still
    going to involve some *arbitrary* instance of your class (e.g. peterb's
    solution, which uses the most recently created instance).  The arbitrary-ness
    doesn't feel right, since it sort of implicitly says that none of the instance
    data is important.  No important instance-specific data sounds like static...

  • How to reference a class without using the new keyword

    I need to access some information from a class using the getter, but I don't want to use the new keyword because it will erase the information in the class. How can I reference the class without using the new keyword.
    ContactInfo c = new ContactInfo(); // problem is here because it erases the info in the class
    c.getFirstName();

    quedogf94 wrote:
    I need to access some information from a class using the getter, but I don't want to use the new keyword because it will erase the information in the class. How can I reference the class without using the new keyword.
    ContactInfo c = new ContactInfo(); // problem is here because it erases the info in the class
    c.getFirstName();No.
    Using new does not erase anything. There's nothing to erase. It's brand new. It creates a new instance, and whatever that constructor puts in there, is there. If you then change the contents of that instance, and you want to see them, you have to have maintained a reference to it somewhere, and access that instance's state through that reference.
    As already stated, you seem to be confused between class and instance, at the very least.
    Run this. Study the output carefully. Make sure you understand why you see what you do. Then, if you're still confused, try to rephrase your question in a way that makes some sense based on what you've observed.
    (And not that accessing a class (static) member through a reference, like foo1.getNumFoos() is syntactically legal, but is bad form, since it looks like you're accessing an instance (non-static) member. I do it here just for demonstration purposes.)
    public class Foo {
      private static int numFoos; // class variable
      private int x; // instance varaible
      public Foo(int x) {
        this.x = x;
        numFoos++;
      // class method
      public static int getNumFoos() {
        return numFoos;
      // instance method 
      public int getX() {
        return x;
      public static void main (String[] args) {
        System.out.println ("Foo.numFoos is " + Foo.getNumFoos ());
        System.out.println ();
        Foo foo1 = new Foo(42);
        System.out.println ("Foo.numFoos is " + Foo.getNumFoos ());
        System.out.println ("foo1.numFoos is " + foo1.getNumFoos ());
        System.out.println ("foo1.x is " + foo1.getX ());
        System.out.println ();
        Foo foo2 = new Foo(666);
        System.out.println ("Foo.numFoos is " + Foo.getNumFoos ());
        System.out.println ("foo1.numFoos is " + foo1.getNumFoos ());
        System.out.println ("foo1.x is " + foo1.getX ());
        System.out.println ("foo2.numFoos is " + foo2.getNumFoos ());
        System.out.println ("foo2.x is " + foo2.getX ());
        System.out.println ();
    }

  • Not able to access the result set from one member function to another

    Im new to jdbc
    I have declared a connection object , a result set object and statement object in one member function and i am not able to access these in another member function. But both are in the same class
    Kindly help
    Thanks
    Shasi

    Kindly refrain from double-posting:
    http://forum.java.sun.com/thread.jspa?threadID=700659&tstart=0
    - Saish

  • Explicit template member function call from return value of function

    i couldn't see this in the list of C++ standards not implemented <http://developers.sun.com/tools/cc/documentation/ss9_docs/mr/READMEs/c++.html> but sun studio 9 doesn't seem to allow explicit calls to template member functions where the left-hand-side is the return value of a function. here's a test-case:
    template <typename T> class Ptr {
    public:
      T* p_;
      Ptr(T* p) : p_(p) { }
      template <typename U> Ptr(const Ptr<U>& u) : p_(u.p_) { }
      template <typename U> Ptr<U> cast() const { return Ptr<U>(*this); }
    class A {
    class B : public A {
    Ptr<A> test_cast_1(const Ptr<B>& b) { return b.cast<A>(); }
    Ptr<A> test_cast_2(const Ptr<B>& b) { return Ptr<B>(b).cast<A>(); }sun studio 9 CC complains with the following message:
    "sunstudio9-template-explicit-call.cc", line 18: Error: Unexpected type name "A" encountered.
    "sunstudio9-template-explicit-call.cc", line 18: Error: Operand expected instead of ")".
    2 Error(s) detected.
    (line 18 is test_cast_2)
    is this a known bug?
    cheers,
    /lib

    you omitted the required keyword template:
    template <typename T> class Ptr {
    public:
      T* p_;
      Ptr(T* p) : p_(p) { }
      template <typename U> Ptr(const Ptr<U>& u) : p_(u.p_) { }
      template <typename U> Ptr<U> cast() const { return Ptr<U>(*this); }
    class A {
    class B : public A {
    Ptr<A> test_cast_1(const Ptr<B>& b) { return b.cast<A>(); }
    Ptr<A> test_cast_2(const Ptr<B>& b) { return Ptr<B>(b).template cast<A>(); }

  • Member function and member procedure inside an object type in Oracle.

    Hi All,
    Please do have a look at these codes and help me understand. I have no idea about this member function and member procedure. How do they work? Please explain me about this.
    Regards,
    BS2012
    create type foo_type as object (
      foo number,
      member procedure proc(p in number),
      member function  func(p in number) return number
    create type body foo_type as
      member procedure proc(p in number) is begin
        foo := p*2;
      end proc;
      member function func(p in number) return number is begin
        return foo/p;
      end func;
    end;
    /

    Methods are just like functions or procedures in a package, except they're not in a package, their part of an object type.
    The object has attributes (which are the variables declared in it).
    To use such an object you would do things like this...
    SQL> set serverout on
    SQL>
    SQL> declare
      2    v_foo foo_type;
      3    v_val number;
      4  begin
      5    v_foo := foo_type(20); -- instantiate the object and initialize the object attributes
      6    v_foo.proc(20); -- call the object method (proc)
      7    v_val := v_foo.func(4); -- call the object method (func)
      8    dbms_output.put_line(v_val);
      9  end;
    10  /
    10
    PL/SQL procedure successfully completed.The Type definition you've declared creates the object class, but not actually an object itself.
    To actually have an object you need to declare a variable of that object class type, and then instantiate it. When you instantiate the object you need to initialize all the attributes (generally you can pass null if required for each of them to initialize them).
    Once you have your object instantiated, you can call the methods within that object as demonstrated above, a bit like calling functions and procedures in a package, except they are methods within the object type itself, and therefore called directly by referencing them from the variable.
    The documentation goes into a lot more detail of objects if you look it up.

  • Cannot call member function on object type

    On 8.1.6 I cannot call a member function from SQL in the way described in the manual.
    The following example is almost copied from the manual:
    create or replace TYPE foo AS OBJECT (a1 NUMBER,
    MEMBER FUNCTION getbar RETURN NUMBER);
    create or replace type body foo is
    MEMBER FUNCTION getbar RETURN NUMBER is
    begin
    return 45;
    end;
    end;
    CREATE TABLE footab(col foo);
    SELECT col,foo.getbar(col) FROM footab; -- OK
    select col,col.getbar() from footab; -- ERROR
    The second select is the way it should be, but I get an error "invalid column name".
    Using the first select, I get the result. This is strange because this is more or less the 'static member' notation (filling in the implicit self parameter myself).
    Is this a known bug in 8.1.6, maybe fixed in later versions?

    Konstantin,
    Did you use loadjava to load the compiled class into the Oracle Database?
    Regards,
    Geoff
    Hello!
    I need to write a member function for object type with java.
    for example:
    create type test as object(
    id number,
    name varchar2(20),
    member function hallo return number);
    create type body test as
    member function hallo return number
    as language java
    name 'test.hallo() return int;
    create table test of test;
    My java-file is:
    public class test {
    public int hallo() {
    return 5;
    select t.hallo() from test t;
    It's does not run. Why?
    I get always an error back. Wrong types or numbers of parameters!!
    please help me.
    thanks in advance
    Konstantin

  • ABAP class or function for retrieving BEx query properties at runtime

    Hello Experts,
    I'm working on BADI RSR_OLAP_BADI and for a special calculation I need to know which characteristics are in the drill-down of the BEX query, sol later on I can aggregate some key figures using only these characteristics.
    Problem is that structure C_s_DATA in method COMPUTE contains all fields of the query (filters, free chars, chars in the rows, etc) and I need to now which characteristics are currently being showing in the Bex analyzer.
    So is there an ABAP class or function module I can use to find out this kind of information at run time?
    Any suggestion?
    Thank you

    Tank you for the feedback,
    I tried to use the class you provided, but I'm stuck now in how to get from within my class that implements RSR_OLAP_BADI interface, a handle, reference, o whatever represent my runtime query (not the query at design time) . As the class you provide must be instantiated before I can use
    In pseudo code could be something like this
    DATA my_query type query_ref.
    my_query = get_rt_query().
    my_query->get_state()
    regards

  • This code executes normally in VS2014, despite the fact that an inline member function is not defined in every TU in which it is odr-used.

    Consider this code:
    header.h:
    #include <iostream>
    class A{
    int i;
    public:
    A() : i(101) {}
    void print();
    void g(A&);
    cpp1:
    #include "header.h"
    inline void A::print() { std::cout << i << '\n'; }
    int main()
    A a;
    a.print();
    g(a);
    cpp2:
    #include "header.h"
    void g(A& a) { a.print(); }
    Note that the member function A::print is defined outside its class with the specifier inline. The code executes normally in VS2014, despite the fact that the member function is odr-used in cpp2, but it is not defined in this file.
    I found the following quotes from the C++11 Standard:
    9.3/3:
    An inline member function (whether static or non-static) may also be defined outside of its class definition provided either its declaration in the class definition or its definition outside of the class definition declares the function as inline.
    3.2/3:
    An inline function shall be defined in every translation unit in which it is odr-used.
    7.1.2/4:
    An inline function shall be defined in every translation unit in which it is odr-used and shall have exactly the same definition in every case.
    The two last quotes above don't speak exactly about a member function but I believe they should be applied in this case too, as the inline specifier is a hint for the compiler to expand the function inline at the point of call. If we assume the compiler
    does this inline expansion, how does it know the definition of the member function, while compiling the cpp2 file?  

    On 12/31/2014 12:13 PM, Belloc wrote:
    C++ is supported on many different systems, with tools provided by many different vendors. Microsoft's linker happens to be pretty smart about merging identical blocks of code. Other toolchains may use linkers that weren't designed with this in mind,
    and that would choke on multiple definitions of the same symbol. The C++ standard is written so that it's actually implementable, on as many platforms as possible.
    Frankly I don't understand your statement above. What would be the difficulty for any compiler*that is already compliant with 3.2/3 and 7.1.2/4*, to adapt its code, so that each call to an inline function in a TU, which doesn't carry the function
    definition, is simply not inlined?
    That's the easy part. The "there's identical function definition in every .obj file, and the linker is expected to merge them all together" is the hard part. Normally, if you define a regular (non-inline) function in more than one source
    file, you get a linker error. Microsoft's linker has a special way to mark "defined more than once, just pick any copy" block of code (see __declspec(selectany) ). Other linkers may not.
    Igor Tandetnik

  • Input solicited: List function support as member functions in CFML

    G'day:
    I'm concerned about how Adobe have implemented the list-oriented member functions in ColdFusion 11. And I was hopeing to capture some community input as to what other people think, before raising it with Adobe:
    Survey: lists in CFML, and the naming of list member functions
    It'd be cool if you could take the time to complete the survey.
    Thanks.
    Adam

    ruerric wrote:
    I created a custom class called Rooms with all the appropriate setters and getters.Arguably, getters and setters are seldom appropriate.
    I iterated through a csv file and input all of the data into my custom object class and then put that object into a list by using list.add().
    Now I want to access the class methods through the use of the list.. how can I do so?
    How I declared my list:
    List list = new ArrayList<Rooms>(); // List implemented as growable array
    Rooms xxx = (Rooms).list.get(20);
    Says illegal start of type error.. What are you actually trying to accomplish here? Is list a static field of Rooms?
    Also, I want to sort the list by the room capacity. My Rooms class has a .setCap and .getCap function but how can I sort the list using that?
    From what I know about list.. it has a sort method but not exactly the way I want to sort a custom made class object..List doesn't have a sort method. There's a method in java.util.Collections to sort a list. I think it's "sort". You can pass it a java.util.Comparator that you write, to sort by whatever criteria you like.
    Question: will the capacity of a room ever change? In real life, if you build a hotel, and a room has a capacity of 3 persons, does the room ever change capacity? If the capacity never changes, then it's debatable whether you really need a setCap() method. It would be better to set the capacity once, in the constructor, and leave it.

  • Using a member function

    Hi all,
    I have a class which is named 'layout1'. This class has a member function called buildLayout(). I can call use the buildLayout() because it is put to static. So normally I can use the function like this:
    layout1.buildLayout()
    But now I want to dynamically select different layouts. After I have selected a layout I will get a string like this "layout1". Is it possible to do something like:
    getClass("layout1").buildLayout() ?????
    I hope someone can help me..
    thx

    I take it you mean you want static members of different classes of a layout type?
    Yes, you can do that by using what's called the "reflection" mechanism.
    Class layoutClass = Class.forName(layoutName); // load class
    Method method = layoutClass.getMethod("buildLayout", new Class[]{});
    method.invoke(null,null);Serveral exceptions need to be handled.

Maybe you are looking for