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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:43:05+00:00 2026-06-18T08:43:05+00:00

I am having a few problems with creating a new class by copying other

  • 0

I am having a few problems with creating a new class by copying other objects to it. From what i can see, the code below works, however my compiler states it’s missing a default constructor of the class material. From what i can see, this is not needed. Am i doing something wrong here?

First class constructor:

    shadingBatch::shadingBatch(const vertexAttribLayout& layout, const material& batchMaterial){
    dataFormat_ = layout;
    batchMaterial_ = *(new material(batchMaterial));
}

I have also tried

shadingBatch::shadingBatch(const vertexAttribLayout& layout, const material& batchMaterial){
            dataFormat_ = layout;
            batchMaterial_ = batchMaterial;
        }

But the same compiler error is returned.

Second class definition

    class material {
protected:
    shader shader_;
public:
    material (const shader* shaderProgram);
    material (const material&);
    ~material();

    void compileShader();
} ;

Second class copy constructor

material::material(const material& other){
        shader_ = *(new shader(other.shader_));
    }

Edit: As requested,

First class definition

class shadingBatch {
    friend class cheeseRenderer;
protected:
    std::vector<primitive*> primitives_;
    std::vector<vertex> vertices_;
    std::vector<GLuint> elements_;
    vertexAttribLayout dataFormat_;
    material batchMaterial_;
    GLuint VAO_;
    GLuint VBO_;
    GLuint EBO_;
public:
    ~shadingBatch();
    GLuint updateBatch (void);
    void addPrimitive (primitive*);
    shadingBatch(const vertexAttribLayout&, const material&);
private:
    void updatePrimitives (void);
    void setVertexAttributes(void);
} ;

And where the constructor is called:

shader* defaultShader = new shader(fragmentSource,vertexSource);
material* defaultMaterial = new material(defaultShader);
vertexAttribLayout* defaultVertexData = new vertexAttribLayout();
shadingBatch* batch = new shadingBatch(*defaultVertexData,*defaultMaterial);
cheeseRenderer renderer(*batch);
  • 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-18T08:43:07+00:00Added an answer on June 18, 2026 at 8:43 am

    What you are doing is not the construction of the objects, but copying the arguments into the internal objects after they have been constructed. You want to look up the concept of initialization lists. The constructor you want to implement looks like this:

    shadingBatch::shadingBatch(const vertexAttribLayout& layout, const material& batchMaterial)
      : dataFormat_(layout), batchMaterial_(batchMaterial) // <-- initialization list
    {}
    

    If you do not initialize you class members explicitly in the initialization list, they will be default constructed. Or at least, the compiler will try. Material seems not to have a default constructor, so the compiler complains in both your attempts.

    Sidenote: the first constructor attempt has another error, a memory leak, since you create an object via new and neither store nor delete the resulting pointer, its memory (and the object itself) will be lost forever.

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

Sidebar

Related Questions

Hi I'm new to Typescript and Javascript and I'm having a few problems creating
I am having a few problems trying to return a table from a SQL
creating a filter for a select menu and having a few problems! the first
Having a few problems with Timers within a service on Win2k3... Basically, creating a
Good Day, I'm having few issues with Doctrine entities generator while creating new project
I'm having a few problems creating a SQL Query. I have the following tables:
So I am having a few problems with settings this up. Let me explain.
I've been having a few problems running PHP-based utilities within the command line ever
hi I'm having a few problems understanding how to control my listeners in bulk.
I've set up django with haystack but im having a few problems. I have

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.