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

  • SEARCH
  • Home
  • 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
The general advice is that you should not call GC.Collect from your code, but
In a class, I've got a trace method that looks like this: [System.Diagnostics.ConditionalAttribute(Trace)] private
For some reason when I call a namespace within this class, I get an
I've got a few methods that should call System.exit() on certain inputs. Unfortunately, testing
What should happen when I call $user->get_email_address() ? Option 1: Pull the email address
After I call getpwuid(uid) , I have a reference to a pointer. Should I
I am building a search box (input field) which should make a server call
private void activateRecords(long[] stuff) { ... api.activateRecords(Arrays.asList(specIdsToActivate)); } Shouldn't this call to Arrays.asList return
My requirement is to call WCF web service from ASP.NET code behind and pass

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.