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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:25:26+00:00 2026-06-09T09:25:26+00:00

Below is the compilation errors I’m getting and the header/cpp files that go with

  • 0

Below is the compilation errors I’m getting and the header/cpp files that go with em. If anyone has a few minutes and a better eye at catching something that I can’t, I would love them forever. This goes back to an a3main.cpp to be tested, so if you need that file fir reference as well just give me a shout. Thanks again!

a3.cpp: In constructor 'disk::disk(int, const char*)': 
a3.cpp:12: error: invalid conversion from 'const char*' to 'char*' 
a3.cpp:12: error:   initializing argument 1 of 'char* strcpy(char*, const char*)' 
a3.cpp: In member function 'void disk::memory(int)': 
a3.cpp:26: error: expected unqualified-id before '=' token 
a3.cpp:28: error: expected primary-expression before '==' token 
a3.cpp: At global scope: 
a3.cpp:37: error: expected initializer before 'mode' 
a3.cpp:42: error: expected initializer before '*' token 
a3.cpp:47: error: expected initializer before 'get_segment'

//a3.cpp
#include <iostream>
#include "disk.h"
#include <iomanip>
#include <cstring>
#include <stdlib.h>
using namespace std;

disk::disk(int num_of_segments, const char* mode)
{
    memory(num_of_segments);
    if(strcmp(mode, "w") || !strcmp(mode, "a"))
        strcpy(mode, mode);

    else
        strcpy(mod, "w");
}   

disk::disk()
{
    memory(20);
    strcpy(mod, "w");
}

void disk::memory(int num)          //private, see header file
{
    segment = new segment[num];
// (nothrow) - page 80 in the text
    if(segment == NULL)
    {
        cerr << "Could not find any data in class ";
        exit(0);
    }
    total = num;
    count = 0;
}

const char* disk::get mode() const
{
    return mode;
}

segment segment* disk::get_all_segment() const
{
    return sgmt;
}

int disk::segment get_segment(int pos) const
{
    segment temp;
    if(pos > 0 && pos < count)
    {
        temp = segment[pos];
    }
    return temp;
}

int disk::get_segment_count() const
{
    return count;
}

disk disk::operator+=(const segment &r)
{
    if(count < total)
    {
        sgmt[count] = r;
        count++;
    }
    return *this;
}

void disk::operator=(const disk &r)
{
    if(*this != &r)
    {
        if(sgmt != NULL)
            delete[] sgmt;
        memory(r.total);
        for(int i=0; i < r.count; i++)
        {
            sgmt[i] = r.sgmt[i];
        }
        count = r.count;
        strcpy(mod, r.mod);
    }
}   

disk::disk(const disk& copy)            //copy constructor
{
    memory(copy.total);
    for(int i=0; i<copy.count; i++)
    {
        sgmt[i] = copy.sgmt[i];
    }
    count = copy.count;
    strcpy(mod, copy.mod);
}

disk::~disk()
{
    if(*sgmt != NULL)
    {
        delete[] sgmt;
    }
}

//disk.h
#include "segment.h"
#include <iomanip>
#include <cstring> class disk {
    private:
        segment *sgmt;
        char mod[3];
        int count, total;
        void memory(int);
    public:
        disk(int, const char *);
        disk( );
        const char* get_mode( ) const;
        segment get_segment(int) const;
        int get_segment_count( ) const;
        const segment* get_all_segments( ) const;
        int access(const char [ ]);
        disk operator+=(const segment &);
        void operator=(const disk &);
        disk(const disk &);
        ~disk( ); };

//segment.h
class segment
{
    private:
        char data[SIZE][41];
    public:
        void initialize(const char [][2000], int);
        void initialize();
        int match(const char []);
        void sort();
        void get_word(char [], int);
        int set_word(const char [], int);
        int set_char(int, int, char);
        char get_char(int, int);
};
  • 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-09T09:25:27+00:00Added an answer on June 9, 2026 at 9:25 am

    You need to just work through the errors one by one, starting at the top.

    The first error is:

    a3.cpp:12: error: invalid conversion from 'const char*' to 'char*' 
    a3.cpp:12: error:   initializing argument 1 of 'char* strcpy(char*, const char*)'
    

    And the referenced line 12 is:

    strcpy(mode, mode);
    

    You declared mode as const char* and the error says strcpy takes char* as its first argument. The error says its invalid to convert const char* to char*. So it should be clear that the error is that you aren’t allowed to pass mode as the first argument to strcpy.

    strcpy(mode, mode); makes no sense and is not allowed. mode cannot be modified but strcpy will modify it. Furthermore, you are trying to copy it over itself, which, if it worked, would do nothing.


    AndreyT is right about these last errors; you have to learn to just go back and re-read the code they point at and see what you did wrong.

    segement in segment = new segment[num]; is a type name, in which case you can’t assign to it like this, or get its value like in if(segment == NULL). You probably mean sgmt.

    In const char* disk::get mode() const you forgot an underscore.

    In segment segment* disk::get_all_segment() const and int disk::segment get_segment(int pos) const you have an extra segments.

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

Sidebar

Related Questions

I am getting an compilation error not a statement for the below code. Not
I am getting compilation error in below code. class A { public: A() {
I have this code below and I'm getting the error upon compilation: error: cannot
the code below gives compilation error when I try to create test t[2]; because
Below is code to an inherited ComboBox. The issue is that the ComboBox is
I have a few Devexpress aspx controls on a website that look fine on
All time am getting below error message in groovy... Could not understand whats causing
I know that android version 2.1 and below do not support GLES20. My code
The overloaded functions compute1() , compute2() , and compute5() cause compilation errors if you
Can anyone explain why I get the following errors when compiling the code shown

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.