Specialization of class template functions

Hello all,
what's wrong with this code? It works just fine with g++.
class Foo {
public:
Foo() { }
template <typename T> void method();
template <> void Foo::method<int>() { }
int main(int argc, char *argv[])
Foo foo;
foo.method<int>(); //OK
Foo& foo_ref = foo;
foo_ref.method<int>(); // Error: Badly formed expression.
Foo foo_arr[10];
foo_arr[0].method<int>(); // Error: Badly formed expression.
return 0;
CC -o foo foo.cc"foo.cc", line 15: Error: Badly formed expression.
"foo.cc", line 18: Error: Badly formed expression.
2 Error(s) detected.
CC -V
CC: Sun WorkShop 6 update 2 C++ 5.3 Patch 111685-06 2002/03/09
-- Michael

You need to invoke as:
foo_ref.template method<int>();
and
foo_arr.template method<int>();
because your opening angle bracket is being parsed as a "less than" operator, because the compiler doesn't realize that its a template. This is a known weirdness of the language. If you have Stroustrup Special Edition, it is explained on page 858, section C.13.6.

Similar Messages

  • Problem - Class containing template functions

    Hi everyone,
    I've written a simple class (not template), containing one template functions, like te following one:
    class MyClass
    public:
    template <typename T>
    typename T::_ptr_type DoSomeThing(int a, int b);
    When I am within a function and I need to call DoSomeThing, I have no problems if I declare a local variable of class MyClass, but I get the following compilation error:
    Error: Unexpected type name "ThirdClass" encountered
    when I use a pointer or a reference to MyClass that is declared elsewhere in the code.
    The following is a sample code that returns me an error:
    int OtherClass::MyFunc()
    m_pMyClass->DoSomeThing<ThirdClass>(10, 20);
    In the above function m_pMyClass is a member variable of OtherClass pointing to an instance of MyClass and ThirdClass is a valid class name (visible to the function).
    Does anyone know why I got the error ?
    Thank you,
    Massimo

    You need to use the syntax:
    m_pMyClass->template DoSomeThing<ThirdClass>(10, 20);
    Really, exactly like I wrote it ;)
    Josh

  • Template function default parameter instantiated unnecessary

    Hi,
    I think the following is valid C++ code. The default parameter of template (member) function should not be instantiated until it is actually required.
    Is it a bug of CC?
    $ cat enumid.cc
    template<class T>
    class TClass
    public:
    void f(int i = T::EnumID);
    class Unknown;
    class X
    public:
    TClass<Unknown> m;
    $ CC -c enumid.cc
    "enumid.cc", line 5: Error: EnumID is not a member of Unknown.
    "enumid.cc", line 11: Where: While specializing "TClass<Unknown>".
    "enumid.cc", line 11: Where: Specialized in non-template code.
    1 Error(s) detected.
    $ CC -V
    CC: Sun C++ 5.8 2005/10/13
    Thanks,
    Qingning

    You are right. This test case is valid and shows compiler bug
    C++ Standard 14.7.1-1
    The implicit instantiation of a class template specialization causes the implicit instantiation of the declarations, but not of the definitions or default arguments, of the class member functions, member classes, static data members and member templates; and it causes the implicit instantiation of the definitions of member anonymous unions.
    If you have a service contract with Sun, please file a bug report via your service channel. You can be kept informed about progress, and get pre-release versions of the compiler that fix the bug.
    If you don't have a service contract with Sun, please file a bug report at bugs.sun.com.
    If you prefer not to file the bug report yourself, let me know, and I'll file one for you.

  • 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.

  • Dreamweaver template function

    I'm working on a site as a favor. I never worked with the
    template function, and just started playing with it. I made a
    template of the site www.negmsc.com. Then, when I create another
    page based off of that template, it looks fine in Dreamweaver but
    when I do a preview in IE, it seems like it's missing a .css file.
    Any ideas?

    That file is not the child page of a DW template.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "pjk91" <[email protected]> wrote in message
    news:fn537t$f2c$[email protected]..
    > I'm working on a site as a favor. I never worked with
    the template
    > function,
    > and just started playing with it. I made a template of
    the site
    > www.negmsc.com.
    > Then, when I create another page based off of that
    template, it looks fine
    > in
    > Dreamweaver but when I do a preview in IE, it seems like
    it's missing a
    > .css
    > file. Any ideas?
    >

  • THE DETACH FROM TEMPLATE FUNCTION IN DREAMWEAVER CC DOES NOT SEEM TO BE FUNCTIONAL Can you please explain.

    The detach from template function in Dreamweaver CC does not seem to be functional
    Can some explain.
    Bruce K.

    Hi Lalita
    Yes you are correct, I TRY THE Modify -> Templates -> Detach from Template.     I have built over 50 websites with this method using Modify -> Templates -> Detach from Template in DW CS5.5
    After a save a page to a template for future ref.
    I create a new page using this temp. but can not use the Modify -> Templates -> Detach from Template. The Detach from Template is not functional. It is there but when I mouse over its not operative.
    Does DW CC need update maybe.
    Thanks
    Bruce

  • Calling a object of class from other class's function with in a package

    Hello Sir,
    I have a package.package have two classes.I want to use object of one class in function of another class of this same package.
    Like that:
    one.java
    package co;
    public class one
    private String aa="Vijay";  //something like
    }main.java:
    package co;
    import java.util.Stack;
    public class main extends Stack
    public void show(one obj)
    push(obj);
    public static void main(String args[])
    main oo=new main();
    }when I compile main class, Its not compile.
    Its give error.can not resolve symbol:
    symbol: class one
    location: class co.main
    public void show(one obj)
                              ^Please help How that compile "Calling a object of class from other class's function with in a package" beacuse I want to use this funda in an application

    kumar.vijaydahiya wrote:
    .It is set in environment variable.path=C:\bea\jdk141_02\bin;.,C:\oraclexe\app\oracle\product\10.2.0\server\bin;. command is:
    c:\Core\co\javac one.javaIts compiled already.
    c:\Core\co\javac main.javaBut it give error.
    Both java classes in co package.Okay, open a command prompt and execute these two commands:
    // to compile both classes:
    javac -cp c:\Core c:\Core\co\*.java
    // to run your main-class:
    java -cp c:\Core co.main

  • Any Class or Function Module..?

    Hi,
    I have a requirement to update some Infotypes when the user updates the salary package from portal.
    Is there any class or Function Module available?
    Pls let me know.
    Thanks,
    KK
    Moderator Message: Thread locked. Points unassigned.
    Edited by: Suhas Saha on Sep 29, 2011 8:38 PM

    Hello,
    I had a similar requirement earlier and I've used the Function modules listed below to update the IT0008, IT0014 & IT0589 respectively.
    HR_SPA_FILL_IT0014_STRUCTURE
    HR_SPA_FILL_IT0008_STRUCTURE
    HR_SPA_FILL_IT0589_STRUCTURE
    Hope this helps.
    Regards,
    Venkata Phani Prasad K

  • Email template functionality in P6

    Hi Experts,
    Do we have any email template functionality in P6,if yes how and where ?
    1.     Option 1 : Send email from project workbench(activity) with logo – Manual process
    2.     Option 2 : Send email with the required content thru BI Publisher.
    Thanks and Regards,
    Aditya

    I am trying to email the activity/task detail to assigned engineer or project status to PM with an email template with company logo.

  • Automatic generation of ABAP-classes from Function Groups?

    Hey there,
    is there a way of having (SE24)-ABAP-Classes generatetd outomaticaly by providing an existing function group?
    I think, the following mapping shold be possible::
    - the function group is the class
    - its function modules are public (static) methods
    - any form-routines are private methods
    -> I don't want to to that boring work myself, some tool should be able to do that just fine, right? So, is there such a tool?
    Thanks, regards
    Joachim

    Sorry, sounds like the only two people who answered are not aware of such a tool...
    There is one additional point, which I hadn't thought about initially. With ABAP OO you also have a much stricter syntax and many more statement variants that are obsolete and thus cannot be used. This is another hindrance for writing such a tool (but of course not impossible, I just kind of doubt that any reasonable programmer would write such a thing).
    Anyhow, I never understood why SAP is pushing OO so much (declaring all non-OO as obsolete), even going as far as implementing stricter syntax checks for OO. In my opinion a much better option would've been to implement some flag that switches on the more strict syntax checks, similarly to the Unicode check they've introduced. Coding in OO or non-OO, both have its use. Rules from SAP to code everything in OO even in cases where OO doesn't work seems straight silly as a general recommendation: E.g. if I have to code an RFC module, why would I want to bloat my code by introducing a class for implementing the functionality so that the RFC is just a wrapper around the class (unless the additional class gives me some real benefit)?
    As much as I appreciate using OO classes supplied by SAP, I often have difficulties seeing objects in the requirements that I have to code (which might of course just be a reflection of my programming skills). A class with just some static methods is often an indication of poor OO design, i.e. there is no reasonable/tangible object and all you have is a utility class with a collection of various methods. To me it's important that the code is well structured, doesn't have any side effects, etc. This can be achieved with non-OO coding as well as OO, but switching from non-OO to OO doesn't guarantee at all that the code is any better.
    In the end, if you just have a single function group, I'd recommend to do the translation manually and try to apply good OO design principles (instead of a straightforward 1-to-1 translation). E.g. for a class with just static methods (which I'd expect an automated translation would result in) one might want to take a peek at [singletons are evil|http://www.c2.com/cgi/wiki?SingletonsAreEvil] versus [singletons are good|http://www.c2.com/cgi/wiki?SingletonsAreGood]. I know it's silly advice if you're a seasoned OO programmer; but if not, I think your time is much better spent by thinking about the design and then applying it instead of using some automated tools where you'd later have to anyhow do some refactoring...

  • 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

  • Class overhead, function overhead and parameter overhead

    Hi all,
    I am interested in class overhead, function overhead (each function in a class) and parameter overhead (each parameter in function).
    I saw somewhere that class overhead are 200 bytes.
    Is it wise to give up on class and go for functional programming? (Only classes required to run the j2me app are created and nothing else)
    How does function get called? Does it work like a stack? Where each parameters get pushed into the stack and later on pop out when control pass on to the function?
    If your program is full of functions doesn't this make it very processor intensive?
    What is the best solution?
    Thanks in advance!

    Hallo,
    silly question: but what exactly do you mean when you say "full of attributes and methods that will never be used for this instance"?
    I assume that when you have created your class you thought about the attributes and methods you wanted to include, and have not included any unnecessary baggage. I can only think that, perhaps, you have a class X that you would like to reuse, because it does all that you want. The only problem is that, for your specific problem, it carries a lot of excess baggage with it. You only need a few of the attributes and methods. Am I correct?
    Such a class reuse will certainly incur some overheads, but let us try to analyse where they are:
    1. Extra Code. The 'big' class is already defined and probably already loaded, so there should not be any overheads for the code.
    2. Extra Data. Certainly creating a new instance of the 'big' class will require more memory. The question is how big is 'big' class, and how many instances do you want to create or have in existance at any one time? If the class is less than a few kB big and you only need a few instances at any one time, then you can afford to ignore the overhead.
    3. Performance. Every time that you create an instance of the 'big' class, the processor must do some work to initialize it. The question is, what is required to initialize the class? This depends on what is in the constructor.
    4. Programmer Time. If there is an existing class, then it will (probably, depending on documentation) take less time to reuse the class
    than to write another, streamlined class. Someone else will already (hopefully) have debugged the 'big' class.
    I think my view would be to reuse 'big' class unless there good grounds not to do so (see above). Your time is more important than a few overheads.

  • 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

  • Equivalent Class for Function Module for VIEW_MAINTENANCE_CALL

    Hi Gurus,
    Can any one let me know
    Equivalent Class for Function Module for VIEW_MAINTENANCE_CALL
    Thanks in a

    Try Class:
    CL_TABLECONTROL
    Or do check if this class is of any use:
    CL_SALV_FULLSCREEN_ADAPTER

  • Dev class for Function Modules

    Hi,
    I am trying to find out any FMs or tables through which the development class(package) can be found out for list of custom Function modules. Currently using TADIR table we can find out dev class for function groups only.
    Thanks
    JLN

    Hi Lakshmi,
    First Go to Table and pass your FM name to Table  ENLFDIR Find Function Group and then go to TADIR Table and pass this FGroup as OBJ_NAME and get the DEVCLASS.
    Use FM
    "RS_ACCESS_PERMISSION
    And Pass Object as FM name Object_CLASS as FUNC and Mode as SHOW you will get all the Details.
    You will get the Details into a Structure header-transpkey(This is a Deep Structure)
    Hope this will give you the Correct Answer.
    Cheerz
    Ram

Maybe you are looking for

  • Performance with Nested Views

    Hello everyone, we are having a performance problem with oracle optimizing nested views. Some with outer joins. One of the guys just sent me the following statement and I'm wondering if anyone can tell me if it sounds correct. The query is about 300

  • Payment method configuration

    Need help in configuring the Wire Payment method without using EDI. I did the config using RFFOUS_T as the payment medium program. But it is not working out. Please provide complete, detailed config steps for setting up this payment method. What shou

  • Query transport error

    Hi All, While transporting query......i.e frm AWB.......transport connector........select objects and when i select required query and transferring i am getting following error Object '0FIN_REP_SIMPL_1_EHP3' (AREA) of type 'InfoArea' is not available

  • Spell Checker Utility

    Hi, I have read that SAP CD provides a spell checker functionnality running on CE 7.1 Here is the information about the product. PdES: SpellChecker Custom Utility by SAP Custom Development [original link is broken] Is it something that comes installe

  • A Combo box has robbed me of my font!

    Here's a good one for you ... I have a textFlow running through columns with a nice embedded font. Looks lovely. I then decide to add a completely unrelated Combo box to my app ... and now the textFlow doesn't render with the font. Comment out the co