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 3481718
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:28:42+00:00 2026-05-18T10:28:42+00:00

I have a class Foo which is used in a small standalone project. It

  • 0

I have a class Foo which is used in a small standalone project. It has a class definition in Foo.h with the implementation for the class’ member functions in an implementation file Foo.cpp.

First question – one of the member functions of class Foo is a template method Foo::doSomething(), is it correct that the implementation of this method should appear with the declaration of the function in Foo.h ?

The template parameter which Foo::doSomething() will be instantiated with is one of two Functor types – class CalcA and CalcB.

Should I:

  • (A) put the defintion and implementation of the two Functor classes all together in Foo.cpp (where they are actually used by the implementation of other Foo member functions to call Foo::doSomething).
  • (B) put the definition and implementation of the two Functor classes in Foo.h.
  • (C) should I put split the definition and implementation of the two Functors across Foo.h and Foo.cpp as would be done with an ordinary class?
  • 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-18T10:28:42+00:00Added an answer on May 18, 2026 at 10:28 am

    General rule:

    If foo::doSomething() is used outside foo.cpp (i.e. if it’s public or protected, usually), it must go in the header.

    If not, putting in in the cpp file is perfectly ok, and even a good idea (as it keeps the clutter away from the header file).

    So, if the functors are only used in the cpp file, by all means put the template function there too. One can always refactor things later if this changes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base class Foo that has an Update() function, which I want
I have a class which is not thread safe: class Foo { /* Abstract
Let's say I have one class Foo that has a bunch of logic in
I have a small application which can be used to set reminders for future
Assume I have a class foo, and wish to use a std::map to store
I have this class. public class Foo { public Guid Id { get; set;
Let's say I have a class: class Foo { public string Bar { get
Let's say I have a class in my web app called class Foo. It
Let's say that I have a class Foo: public class Foo { public static
For example, suppose I have a class: class Foo { public: std::string& Name() {

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.