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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:10:02+00:00 2026-06-18T02:10:02+00:00

I have 3 classes. class piesa_a{ protected: int id; char *tip; int pret; public:

  • 0

I have 3 classes.

class piesa_a{

protected:

    int id;
    char *tip;
    int pret;

public:
[custructor with/without param, display function - works well each one of it]




class piesa_b:public piesa_a
{

private:
    float lungime;
    bool bw;
public:
[custructor with/without param, display function - works well each one of it]

class piesa_c:public piesa_a
{

    private:
        int nr;
        piesa_b *buf;
    public:
        piesa_c():piesa_a(){nr=0; buf = new piesa_b[nr];}
        piesa_c(int n, piesa_b *bu,int aid, char *tipi, int pretzz):piesa_a(aid,tipi,pretzz) 
        {
            buf = new piesa_b[nr];
            for(int i=0;i<nr;i++)
                buf[i]= bu[i];
        }
    void afisare()
    {

        cout<<nr;

    }

In main i have this:

piesa_c C(2, H,14,"TIPC",20);


C.afisare();

But this doesn’t work.
I don’t know if the “buf” was declared properly because the problem seems to be in last class.
Why?

Later Edit:
The entire code is here: http://pastebin.com/nx2FGSfe.

Now, i have this in main

int main(int argc, char** argv) {

    piesa_b *H;
            H = new piesa_b[2];

    piesa_a A(4,"TIPA",120);
    piesa_b B(100,1,3,"TIPA",120);
    H[0]=B;
    H[1]=B;
    piesa_c C(2, H,14,"TIPC",20);

    piesa_a** v = new piesa_a*[3];

    v[0] = &A;
    v[1] = &B;
    v[2] = &C;

    for(int i=0;i<3;i++)
        v[i].afisare();

    return 0;
}

The display function return this error

main.cpp:143:14: error: request for member ‘afisare’ in ‘*(v + ((unsigned int)(((unsigned int)i) * 4u)))’, which is of non-class type ‘piesa_a*’
  • 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-18T02:10:03+00:00Added an answer on June 18, 2026 at 2:10 am

    nr is not initialized in the piesa_c() constructor, meaning it will have an undefined value.

    Instead of using a dynamically allocated array used a std::vector<piesa_b> instead. It will handle dynamic memory allocation and do the right thing when instances of piesa_c is copied. Using std::vector also means the nr member variable can omitted as that information can be obtained from vector::size() and the std::vector can be populated in the initializer list instead of in the constructor body:

    std::vector<piesa_b> buf;
    
    piesa_c(int      n,
            piesa_b *bu,
            int      aid,
            char*    tipi,
            int pretzz) : piesa_a(aid,tipi,pretzz),
                          buf(bu, bu + nr) {}
    

    And to invoke a member function on each element in buf:

    // C++11 lambda, otherwise use
    // std::vector<piesa_b>::const_iterator.
    //
    std::for_each(buf.begin(), buf.end(), [](piesa_b& pb) { pb.afisare(); });
    

    If afisare() does not modify then make it const:

    void afisare() const
    {
    }
    

    Additonally, use std::string instead of char*. If you insist on having dynamically allocated members in the classes you need to obey the rule of three.

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

Sidebar

Related Questions

Suppose we have two classes: class Base { private: int x; public: void f();
I have classes public class BlogPost { public int Id {get;set;} public string Body{get;set;}
I have two classes: class ClassA { public: ClassB *classB; int i = 100;
I have two classes: class OrdenO { public int id_orden_O {get;set;} public int Ei_O
I have two classes: class A { public: int i; }; class B :
I have two classes: class Foo{ public int FooId { get; set; } ...
I have 2 classes: class A { public: char * x; char * y;
Lets say I have these classes: class Foo { public $_data; public function addObject($obj)
I have two classes class a { public: a(int i); }; class b {
I have 2 classes: class Base { public: virtual int Foo(int n); virtual void

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.