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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:55:07+00:00 2026-06-12T13:55:07+00:00

Possible Duplicate: Error on calling default constructor with empty set of brackets When I

  • 0

Possible Duplicate:
Error on calling default constructor with empty set of brackets

When I run this I get the compiler warning:34 [Warning] the address of`Rational test4(), will always evaluate as true. but I am trying to make it so that the default constructor is the rational number 0/1. Line 34 is is int main() the line: cout << test4;.

#include <iostream>

using namespace std;

class Rational
{
public:
       Rational();

       friend ostream& operator <<(ostream& out,Rational rational1);


private:
        int numerator;
        int denominator;

};

int main()
{
    //Rational test1(24,6), test2(24);
    Rational test4();
    //cout << test1<< endl;
    //cout << test2<< endl;
    cout << test4;
    system("pause");
}

Rational::Rational() : numerator(0), denominator(1)
{ 
    //empty body
}

ostream& operator <<(ostream& out,Rational rational1)
{
       out << rational1.numerator <<"/"<<rational1.denominator;
       return out;
}
  • 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-12T13:55:08+00:00Added an answer on June 12, 2026 at 1:55 pm

    The reason your program prints “1” is because Rational test4(); declares a function pointer. So how does std::cout print a function pointer? It involves automatic conversions. First look to plain old data pointers. The I/O machinery does not have a mechanism for printing a double* pointer, or a MyClass* pointer, or any of the myriad number of pointers that can arise. What the I/O machinery can do have is a mechanism to print a void* pointer. Thanks to implicit conversions, that same mechanism works for double* and MyClass* pointers because all pointers convert to void* pointers.

    Function pointers don’t convert to void*. Function pointers are not pointers! The only available conversion is to a boolean. That conversion to boolean is what let’s you do stuff like if (function_pointer) do_something(); Your function pointer isn’t null, so on conversion to bool it becomes true, which prints as 1.

    The solution is simple: Change that Rational test4(); to Rationaltest4;`,

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

Sidebar

Related Questions

Possible Duplicate: Error on calling default constructor with empty set of brackets Why does
Possible Duplicate: Error on calling default constructor with empty set of brackets What's the
Possible Duplicate: Why is it an error to use an empty set of brackets
Possible Duplicate: Why is it an error to use an empty set of brackets
Possible Duplicate: Why is it an error to use an empty set of brackets
Possible Duplicate: PHP ToString() equivalent I get this error: Catchable fatal error: Object of
Possible Duplicate: C++ virtual function from constructor Calling virtual functions inside constructors This question
Possible Duplicate: Error with address of parenthesized member function In this recent question the
Possible Duplicate: Make error: missing separator I am so stressed out by this silly
Possible Duplicate: Foursquare API for venue user image error I first noticed this problem

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.