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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:23:16+00:00 2026-06-07T13:23:16+00:00

this is the cpp of a Time function. The code is defining functions of

  • 0

this is the cpp of a Time function. The code is defining functions of a time.h file on this time.cpp. My question is: How come this function definition is possible if the functions inside this fct are defined afterwards? Thank you

void Time::setTime(int hour, int minute, int second)
{
    sethour(hour);
    setminute(minute);
    setseconds(seconds);
}

void Time::sethour( int h)
{ ....
  • 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-06-07T13:23:18+00:00Added an answer on June 7, 2026 at 1:23 pm

    You don’t need a definition to call a function, you only need a declaration. The compiler is happy with the declaration alone. The linker requires code to be generated, and it requires the definition, but it doesn’t matter when you define them, as long as you do.

    In your case, the declaration of every member function is visible to all other member function, even if inside the class definition it came afterwards:

    class Time
    {
       void setTime();  //setTime knows about sethour even if it's before
       void sethour();
    };
    

    Outside of a class, this doesn’t hold, meaning you need a declaration before using a method. The declaration is just the prototype:

    void foo();
    void goo()
    {
        foo(); //can call foo here even if it's just declared and not defined
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting this error during compile time (g++ 4.4.6): main.cpp: In function ‘int
I occasionally write code something like this: // file1.cpp #define DO_THIS 1 #if DO_THIS
It made some errors like this: KDnsCache.cpp: In member function ‘unsigned int KDnsCache::GetName(const char*)’:
I need to change this code to cpp code This is the c# code
This is one of my most dreaded C/C++ compiler errors: file.cpp(3124) : fatal error
Why does this code execute perfectly on Dev-CPP but fails to execute on Borland
I've written a .cpp file with a number of functions in it, and now
I've posted a similar topic/question, but this time it's a bit different. I'm just
I'm getting two compile errors: /home/sater/projects/MotionManager/videoProcess.cpp:11:1: error: a function-definition is not allowed here before
This error is inexplicably occurring. Here is the code and output: timer.cpp: #include timer.h

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.