-4
class box{
    int l,w,h;
    box(int a,int b,int c){
        l = a;w = b;h = c;
    };
    
};
bool cmp(box a,box b){
    return a.l*a.w<b.l*b.w;
}
class Solution{
    public:
    
    /*The function takes an array of heights, width and 
    length as its 3 arguments where each index i value 
    determines the height, width, length of the ith box. 
    Here n is the total no of boxes.*/
    int maxHeight(int h[],int w[],int l[],int n)
    {
        //Your code here
        struct box b[(3*n)]={};
        int j = 0;
        for(int i = 0 ; i< n; ++ i){
            b[j++] = box(min(l[i],w[i]),max(l[i],w[i]),h[i]);
            b[j++] = box(min(l[i],h[i]),max(l[i],h[i]),w[i]);
            b[j++] = box(min(w[i],h[i]),max(w[i],h[i]),l[i]);
        }
        n*=3;
        sort(b,b+n,cmp);
        int dp[n];
        for(int i = 0 ; i< n; ++ i){
            dp[i] = b[i].h;
        }
        int ans = INT_MIN;
        for(int i = 1; i< n; ++ i){
            for(int j = 0; j< i; ++ j){
                if(b[i].l>b[j].l and b[i].w>b[j].w and dp[i]<dp[j]+b[i].h)
                dp[i] = b[i].h+dp[j];
            }
            ans = max(ans,dp[i]);
        }
        return ans;
    }
};

The code above shows an error that struct variables takes 3 arguments and only 1 given as shown. Please help me out of this. Thanks.

Also please provide some good references from where I could get more idea on these kinds of topics. Like sites from where I could learn these type of hints and secrets of language. enter image description here

  • 1
    The error message doesn't match the code you're showing. – lurker Apr 18 '22 at 15:14
  • Sorry, I changed it. – HARSH KUMAR CHOUDHARY Apr 18 '22 at 15:15
  • 1
    [Why should I not upload images of code/data/errors when asking a question?](https://meta.stackoverflow.com/q/285551/995714). Copy the error text and paste here in proper format – phuclv Apr 18 '22 at 15:21
  • It's not a good idea to learn C++ via "coding" websites unless you want to learn how to write extremely bad code. Prefer good [books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) instead. – Evg Apr 18 '22 at 15:57

1 Answers1

-3

I got it. Here I had not written the default initializers functions and that is why it is showing this error. Also I need to change the access modifier to public. So I changed the code of struct declaration to something like this.

enter image description here

  • 3
    It's Ok to answer your own question on SO, but you will need to elaborate and show your solution or it may get downvoted as an insufficiently written answer. – lurker Apr 18 '22 at 15:15
  • Ok, I will take care of it. – HARSH KUMAR CHOUDHARY Apr 18 '22 at 15:18
  • 6
    Also never include code as images – Lala5th Apr 18 '22 at 15:20
  • I see absolutely zero initialization occurring. I see plenty of assigment. – Taekahn Apr 18 '22 at 15:20
  • 1
    [https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors-when-asking-a-question](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors-when-asking-a-question) – drescherjm Apr 18 '22 at 15:21