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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:19:51+00:00 2026-06-12T02:19:51+00:00

I have been learning on classes in c++ and I got a certain code

  • 0

I have been learning on classes in c++ and I got a certain code from an old russian book its about a book class, I tried modifying it and running it its not working may some help me understanding why the authour used this code(what does strdup do?)

Author = strdup(autho);

inside the constructor and was wrong with this line of code

Book s("edgar", "science", "chemistry for dummies", "502","12.11.13","1.12.96");

Anyone with a simple straight explanation?

Main code below

using namespace std;

class Book{

    char * Author;
    char * Type;
    char * Title;
    int * Pages;
    unsigned int * Yearpublished;
    unsigned int  * Publishing;

    Book(char * autho, char * type, char * title,   int * pages, unsigned int * yearpublished, unsigned int  * publishing ){

        Author = strdup(autho);
        Type = strdup(type);
        Title = strdup(title);
        Pages = pages;
        Yearpublished = yearpublished;
        Publishing = publishing;

    }

    ~Book(){

        if(Author != NULL){

             free(Author);

        }
        if(Type != NULL){

            free(Type);
        }

        if(Title != NULL){

            free(Title);
        }
    }

};

int main(){

    cout << "main start" << endl;

    Book s("edgar", "science", "chemistry for dummies", "502","12.11.13","1.12.96");

    cout << "main finish" << endl;
return 0;
}
  • 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-12T02:19:53+00:00Added an answer on June 12, 2026 at 2:19 am

    There are many, many things wrong with the code posted. So many things that virtually every single line is in error.

    One of the most obvious is that you’re trying to store a year as an int *, and then passing in a string containing "12.11.13". That doesn’t work. You’re doing the same for pages; accepting an int* and passing in a string containing an int. You can’t do that, that isn’t how pointers work. Most of your usage of pointers indicates that you don’t really know what the * does, and you should stop and read about pointers before you introduce some very difficult to track down bugs into your code. You should either store your year as a string (very bad idea) or store it as an integer in unix time, which is pretty standard.

    You should remove using namespace std and replace it with #include <string>. You should throw out all the lines that start with char*, and replace them with std::string and throw out your int* lines and make them int.

    You’re also declaring a private constructor and destructor. You need to add public: after the member variable declarations but before Book(). Then you should throw out the body of your constructor and use initializer lists.

    You’re also not including <iostream>, so your cout calls are probably causing errors.

    Once you’ve done the above, you should remove the destructor ~Book() completely.

    For example:

    class Book{
    
        std::string Author;
        // ...
        int Pages;
        // ...
    
        public:
    
        Book(std::string author, /* ... */ int pages /* ... */)
        : Author(author), Pages(pages) {
    
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I come from classes object orientation languages and recently I have been learning those
I have been learning about Delegation and Data Sources for iOS programming and need
I'm 14 and have been learning java for about 4/5 months. I'm coding a
I am just learning how to use classes in my projects. I have been
I have been trying to learn about classes in PHP and part of my
I've been learning about classes in JavaScript, the use of prototype and finally how
I have been learning Objective-C as my first language and understand Classes, Objects, instances,
I've been learning Ruby for a class and have been writing a sample game.
I have been following a workshop whilst I'm learning C#. One of the class
I have been learning NodeJS recently. It seems to be standard in the Node

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.