0

I was writing a data structure but suddenly after a little coding a strange error gives that no operator">>" matches these operends and also no operator"=" matches these operends .

its just after if (right==1) in the cin>>a[i] and a[i]= mininfinitive

the code :

#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <assert.h>
#include <ctime>
#include <bitset>
#include <numeric>
#include <complex>
using namespace std;

#define int long long int
#define maxinfinitive 9223372036854775807
#define mininfinitive -9223372036854775807

int a[100];

struct heapnode
{
    heapnode* childs[100];
    int k,number;
    heapnode* right;
};

struct binomialheapstart
{
    heapnode* starter;
};

int memberstotal(int k)
{
    if (k==0) return 0;
    if (k==1) return 1;
    else 
    {
        int n=0;
        for (int i=1;i<k;i++)
            n+=memberstotal(i);
        n++;
        return n;
    }
}

binomialheapstart bhs[100];

void filll(int num , int bet , heapnode* here)
{
    here->number = a[bet];
    bet++;
    for (int i=1;i<num;i++)
    {
        here->childs[i] = new heapnode();
        int q;
        q = memberstotal(i);
        filll(i,bet,here->childs[i]);
        bet += q;
    }
}

void main()
{
    int n;
    string cmd;
    for (int i=0;i<100;i++)
        bhs[i].starter=0;
    cout<<"We have insert heap, insert binomialheap and merge binomialheap and exit command as ih , ib , me , ex commands"<<endl;
    cin>>cmd;
    while(cmd!="ex")
    {
        if (cmd=="ib")
        {
            cout<<"the number of the array?";
            cin>>n;
            if (bhs[n].starter!=0) cout<<"It already exists!"<<endl;
            else
            {
                cout<<"you must give a starting heap , enter K number!"<<endl;
                cin>>n;
                int con = memberstotal(n);
                cout<<"you must give "<<con<<" member!"<<endl;
                for (int i=0;i<100;i++)
                    a[i]=mininfinitive;
                for (int i=0;i<con;i++)
                        cin>>a[i];
                sort(a,a+con);
                bhs[n].starter = new heapnode();
                bhs[n].starter->k = n;
                filll (n , 0 , bhs[n].starter);
                cout<<"Added"<<endl;

            }
        }
        if (cmd=="ih")
        {
            cout<<"the number of the array?"<<endl;
            cin>>n;
            if (bhs[n].starter==0) cout<<"It doesen't exist!"<<endl;
            else
            {
                heapnode* a = bhs[n].starter;
                int right=0;
                int k;
                cout<<"give the heap K number!"<<endl;
                cin>>k;
                while (right==0)
                {
                    if (a->k==k) right=2;
                    if (a->right!=0) a=a->right; else right=1;
                }
                if (right==2) cout<<"A heap with this K number exists!"<<endl;
                if (right==1)
                {
                    int con;
                    con = memberstotal(k);
                    cout<<"you must give "<<con<<" member!";
                    for (int i=0;i<100;i++)
                        a[i]=mininfinitive;
                    for (int i=0;i<con;i++)
                        cin>>a[i];

                }
            }
        }
        cin>>cmd;
    }
}
2
Contributors
1
Reply
13
Views
3 Years
Discussion Span
Last Post by Moschops
0

a[i] is an object of type heapnode. mininfinitive looks like a long. You have not taught the compiler what the operator = means when you use it with a heapnode and a long. What are you expecting to happen? It makes no sense to say that a heapnode object (which contains an array, a pointre, and two int values) equals a single long.

Same with cin>>a[i]; You type something on the keyboard. How is the compiler meant to know what to do with that typed input to populate heapnode object? You have to write that functionality yourself.

Also, in C++ main returns an int. It does not, and never has, returned a void.

#define int long long int is hideous. Consider a typedef instead.

Edited by Moschops

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.