Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5982861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:08:52+00:00 2026-05-22T22:08:52+00:00

How should I call a method within a defined class from a template class

  • 0

How should I call a method within a defined class from a template class method?
Below is my scenario –

  1. Template Class

    template <class T>
    class TC {
        void myTemplateMethod() {
            T.myMethod();  //can I call like this ?
        }
    }; 
    
  2. Defined Class

    class tdef {
        void myMethod() { 
            //does something
        }
    };
    
  3. Main

    int main()  {
        TC<tdef> tobj;
        tobj.myTemplateMethod(); //can I call tdef.myMethod() like this?
    }
    

Just to note, that I have debugged a code like this and have found that tdef.myMethod() does not work when called like this. Also are there any chances that some exceptions are not handled while calling tdef.myMethod() from within Template class method?

-Somnath

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:08:53+00:00Added an answer on May 22, 2026 at 10:08 pm

    That’s a non-static member function, so it can only be called on an instance. Templates don’t change that fact.

    T t;
    t.myMethod();
    

    or if the function were static:

    T::myMethod();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I need to call some action method of a controller from within javascript
when overriding the loadView method in UIViewController, should one call [super loadView] in the
How often should I call OpenGL functions like glEnable() or glEnableClientState() and their corresponding
The general advice is that you should not call GC.Collect from your code, but
To authanticate users in Asp.net Membership we can call method FormsAuthentication.Authenticate(username, password) how can
I've got a few methods that should call System.exit() on certain inputs. Unfortunately, testing
I have some ctypes bindings, and for each body.New I should call body.Free. The
Many GDI+ classes implement IDisposable, but I'm not sure when I should call Dispose.
I have two WIN32 DLL projects in the solution, main.dll should call a function
http://code.google.com/appengine/docs/python/tools/uploadingdata.html is not clearly understand. Where i should call the bulkloader.py or appcfg.py? Should

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.