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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:41:07+00:00 2026-05-16T14:41:07+00:00

I’ve been working through Bjarne Stroustrup’s The C++ Programming Language (2nd edition – I

  • 0

I’ve been working through Bjarne Stroustrup’s “The C++ Programming Language” (2nd edition – I know I should really get a new copy but this is a library book!), and had a few questions about one of his simpler questions. In Chapter 2, when talking about Declarations and Constants, he lists a set of declarations, some of which are definitions as well. In an exercise at the end of the chapter, he challenges the reader to go back and re-write the list, this time changing all of the defined declarations to just declarations and changing all of the non-defined ones to have a definition.

I have completed this task, hopefully mostly correctly, but there were a few parts I got stuck on. I would appreciate it if anyone could take a quick look through my list, check if there are any of the original list I mis-allocated, and then check my changes – including most specifically how to declare but not define a typedef, and if my enum declaration-not-definition is right. Thanks very much to anyone who helps. I apologise since this isn’t strictly a direct code question – i.e. there’s no compilable code here, it’s more… I dunno. But it does have code in it, so I hope that’s okay.

// Original:

/*

char ch;                                                    // Definition.
int count = 1;                                              // Definition.
char* name = "Njal";                                        // Definition.
struct complex { float re, im; };                           // Definition.
complex cvar;                                               // Definition.
extern complex sqrt(complex);                               // Declaration, NOT definition.
extern int error_number;                                    // Declaration, NOT definition.
typedef complex point;                                      // Definition.
float real(complex* p) { return p->re; }                    // Definition.
const double pi = 3.1415926535897932385;                    // Definition.
struct user;                                                // Declaration, NOT definition.
template<class T> abs(T a) { return a < 0 ? -a : a; }       // Definition.
enum beer { Carlsberg, Tuborg, Thor };                      // Definition.

*/

// Definitions/Declarations switched:

/*
extern char ch;
extern int count;
extern char* name;
struct complex;
extern complex cvar;
complex sqrt(complex in) {                                  // Yes, my maths may be wrong here. Doing the actual maths from memory.
    complex out;
    out.re = (in.re * in.re) - (in.im * in.im);
    out.im = (in.re * in.im)*2;
    return out;
}
int error_number;
                                                            // No idea how to declare but not define a typedef!
float real(complex* p);
extern const double pi;
struct user { string name; int age; char gender; };         // Lets assume we include <string>, and yes, using int for age *might* be a bit wasteful, but meh.
template<class T> abs(T a);
extern enum beer;                                           // Not sure if this is right.

*/
  • 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-16T14:41:07+00:00Added an answer on May 16, 2026 at 2:41 pm

    typedef complex point; is not a definition in C++, but only in C.

    You also cannot, from what I know, provide a non-defining declaration for pi without changing its meaning, because the definition it shows has internal linkage, but if you put extern const double pi; you will give it external linkage (possibly conflicting with other translation units’s pi names). Note that linkage rules are complicated

    static int a;
    extern int a; // valid, 'a' still internal
    
    extern int b;
    static int b; // invalid!
    
    const double pi1 = 3.14;
    extern const double pi1; // valid, and 'pi1' is internal
    
    extern const double pi2;
    const double pi2 = 3.14; // valid, but 'pi2' is now external
    

    You also cannot only declare an enumeration without defining it.

    I believe your other solutions are correct.

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

Sidebar

Ask A Question

Stats

  • Questions 513k
  • Answers 513k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Well, I haven't disassembled the machine code in there, but… May 16, 2026 at 5:53 pm
  • Editorial Team
    Editorial Team added an answer I think I found the problem. If you make up… May 16, 2026 at 5:53 pm
  • Editorial Team
    Editorial Team added an answer Sending/Receiving data with a specific length comes to mind, ie.… May 16, 2026 at 5:53 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm looking for suggestions for debugging... If you view this site in Firefox or
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.