problem of creating objects from another classes

Pages: 123
this is the bptree2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef B_PLUS_TREE2
#define B_PLUS_TREE2

#include <iostream>
#include <ostream>
#include <stdio.h>
#include <stdlib.h>
#include "bptree.h"
using namespace std;
class internalslot
		{
		  public:
			int st;//start time
			int et;//end time
			
		};//end class internal 

	class internal_container
		{
		  public:

			internalslot *in_node;
			long *keys;
			internal_container *next_incont;
internal_container()
    {
         keys=new long;
        in_node= new internalslot;
	 next_incont= NULL;
    }
			internal_container(int mk, int ms)
				{
			     keys=new long [mk];
				in_node= new internalslot [ms];
				next_incont= NULL;
				 }

		};//end class internal_container
	
	class leafslot
		{
		  public:
			int st;
			int et;
			string mob_id;
			
		};//end class leaf

	class leaf_container
		{
		  public:
			leafslot *leaf_node;
			leaf_container *next_leafcont;
leaf_container(){
leaf_node=new leafslot; 
				next_leafcont=NULL;}
			leaf_container( int ms)
		        {
				leaf_node=new leafslot[ms]; 
				next_leafcont=NULL;
			}

		};//end class leaf_container

 
//}; ///end class bptree	


#endif   

and this is the bptree.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef B_PLUS_TREE
#define B_PLUS_TREE
#include <iostream>
#include <ostream>
#include <stdio.h>
#include <stdlib.h>
#include "bptree2.h"
using namespace std;
class bptree
    {
	public:
		
		int max_key;
		int max_slot;
		int cur_key;
		int cur_leaf_slot;
		int cur_in_slot;
		bptree * head;
		internal_container incont;
		leaf_container leafcont;
		void insert(string , int , int );
		void insert_leaf(string , int , int );
		void insert_internal(int , int );
		void newleafcont(int , int );
		void print();
		void newintcont();

		//initilization
		bptree(int mk,int ms)
		    {
			max_key = mk;
			max_slot=ms;
			cur_leaf_slot=0;
			cur_key= 0;
			cur_in_slot=0;
			head=NULL;
			
//incont= internal_container(max_key, max_slot);
leaf_container leafcont = leaf_container (max_slot);
internal_container incont= internal_container(max_key, max_slot);

		    }
	};//end class bptree


#endif 


and the bptree.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
 #include <iostream>
#include <ostream>
#include "bptree.h"
#include "bptree2.h"
using namespace std;
void bptree::newleafcont(int st,int et)
	{
		
//***************************************************
// i want to create another object of leaf_container
// but i think it is rong way !!!!!!!!!!!!!!
//*****************************************************
leaf_container leafcont = leaf_container (max_slot);
 
		incont.keys[cur_key] = (long )&leafcont;
		cout<<endl<<"   key"<<cur_key<<"     incont.keys[cur_key]   "<<incont.keys[cur_key] <<"   (long )&leafcont   "<< (long )&leafcont<<endl;
		cur_key++;
		cout<<"key  "<<cur_key;		

	};
void bptree::insert_internal(int st, int et)
{
                incont.in_node[cur_in_slot].st=st;
		incont.in_node[cur_in_slot].et=et;
                cur_in_slot++;
};
void bptree::insert_leaf(string mob_id, int st, int et)

	{
		leafcont.leaf_node[cur_leaf_slot].st=st; 
		leafcont.leaf_node[cur_leaf_slot].et=et;

//***************************************
//i dont know why the code broken in this point after second insertion
// so i make this statement comment,,, and then it is ok 
// but i need to make it statment

		//leafcont.leaf_node[cur_leaf_slot].mob_id=mob_id;
//*****************************************************
		cur_leaf_slot++;	
		cout<<"finish insert_leaf"<<endl;		 
	};
void bptree::insert(string mob_id, int st, int et)
 {

	if(head==NULL)
            {
cout<<endl<<"null"<<endl;
		insert_internal(st, et);

		insert_leaf(mob_id, st, et);

        	incont.keys[cur_key] = (long )&leafcont;

		head=( bptree *)&incont;
		cur_key++;
		cout<<endl<<"incont.keys[cur_key]"<<incont.keys[0]<<"key   "<<cur_key;	
	cout<<endl<<"null"<<endl;		
	    }//end if
	else//head!=NULL
	   {
		if(cur_leaf_slot==max_slot)
		{
			cout<<"        curleaf==maxslot         ";
			newleafcont(st, et);
			cur_leaf_slot=0;
		}

		 if((cur_leaf_slot<max_slot)&&(cur_in_slot<max_slot) )

	 	{
			cout<<endl<<" not null  curentleaf  "<<cur_leaf_slot<<"    maxslot   "<<max_slot<<"       curinternal  "<<cur_in_slot<<endl;
			
			insert_leaf(mob_id, st, et);

			if (incont.in_node[cur_in_slot-1].et<et)
			{
			incont.in_node[cur_in_slot-1].et=et;
			
			}

			
			}//end else if(cur_leaf_slot<max_slot)
}//end  head !=null

 };  //end insert



int main()          
{       
bptree tree(4,3);
tree.insert("m4", 1, 7);

tree.insert("m2", 2, 8);
 tree.insert("m1", 3, 12);
 tree.insert("m6", 4, 12);
 tree.insert("m0", 5, 12);
 tree.insert("m6", 6, 3);
 tree.insert("m9", 7, 20);
//tree.print();
return 0; 
}///end main
           



i have problems with creation of objects from another classes i want to creat leaf_container object and internal_container object in the bptree class and then recreate another leaf_container objects and internal_container objects in another time,,,,,
i think the definitions is rong........


please help
Last edited on
what error does these lines give to you??

1
2
3
leafcont= new leaf_container(max_slot);
 incont=new internal_container(max_key, max_slot);
leafcont=new leaf_container(max_slot);

this code will not compile.

if statement is ending with a semicolon!!!
1
2
3
4
if (incont.in_node[cur_in_slot-1].et<et);
{
incont.in_node[cur_in_slot-1].et=et;
}


you need to overload << for this code.
cout <<endl<<"x= "<<x<< " leafcont.leaf_node[x].st=st "<<leafcont.leaf_node[x].st<<" leafcont.leaf_node[x].et "<<leafcont.leaf_node[x].et<<" leafcont.leaf_node[x].mob_id "<<leafcont.leaf_node[x].mob_id<<endl;


1
2
3
incont = new internal_container(max_key, max_slot);
leafcont=new leaf_container(max_slot);
leafcont= new leaf_container(max_slot);


both incont and leafcont are not pointers!!!

declare this way:
1
2
internal_container *incont;
leaf_container *leafcont;
1
2
3
4
5
both incont and leafcont are not pointers!!!

declare this way:
internal_container *incont;
leaf_container *leafcont;

if i declare it like this ,,, it gives me erros in each call,,, like:
error: request for member ‘keys’ in ‘((bptree*)this)->bptree::incont’, which is of non-class type ‘internal_container*’

error: request for member ‘in_node’ in ‘((bptree*)this)->bptree::incont’, which is of non-class type ‘internal_container*’



i edit the sent code,,, please look to it again..................

thanks in advance


i edit the code now,, please recheck it ,,,,,,,,,,,

my problem is in the bptree.cpp,, it is compiled ,but it give me rong answers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void bptree::newleafcont(int st,int et)
	{
		
//***************************************************
// i want to create another object of leaf_container
// but i think it is rong way !!!!!!!!!!!!!!
//*****************************************************
leaf_container leafcont = leaf_container (max_slot);
 
		incont.keys[cur_key] = (long )&leafcont;
		cout<<endl<<"   key"<<cur_key<<"     incont.keys[cur_key]   "<<incont.keys[cur_key] <<"   (long )&leafcont   "<< (long )&leafcont<<endl;
		cur_key++;
		cout<<"key  "<<cur_key;		

	};


in this code i want to create new leaf_container object and assign the new address to the incont.keys[cur_key] ,,,, the address value not changed after second calling of this function,,,and overwrite the old value !!!!!!!!!!!!!!!!!!!!!!!!!!!!
change each "." to de-reference operator as everything is now pointer.
like:

1
2
3
incont.keys[cur_key] = (long )&leafcont;
to
incont->keys[cur_key] = (long )&leafcont;
i did it for you now tell me what problem is left...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <ostream>
#include "bptree.h"
#include "bptree2.h"
using namespace std;
void bptree::newleafcont(int st,int et)
	{
		//*****************************************
               //******* another problem*******************
               //******************************************

                 leafcont= new leaf_container(max_slot);
		
                incont->keys[cur_key] = (long )&leafcont;
         	cur_key++;


	};
void bptree::insert_internal(int st, int et)
{
                incont->in_node[cur_in_slot].st=st;
		incont->in_node[cur_in_slot].et=et;
                cur_in_slot++;
};
void bptree::insert_leaf(string mob_id, int st, int et)

	{
		leafcont->leaf_node[cur_leaf_slot].st=st;
		leafcont->leaf_node[cur_leaf_slot].et=et;
		leafcont->leaf_node[cur_leaf_slot].mob_id=mob_id;
		cur_leaf_slot++;			 
	};
void bptree::insert(string mob_id, int st, int et)
 {

	if(head==NULL)
            {
		insert_internal(st, et);
		insert_leaf(mob_id, st, et);
        	incont->keys[cur_key] = (long )&leafcont;
		head=( bptree *)&incont;
		cur_key++;
					
	    }//end if
	else//head!=NULL
	   {
		if(cur_leaf_slot==max_slot)
		{
			cout<<"        curleaf==maxslot         ";
			newleafcont(st, et);
			cur_leaf_slot=0;
		}

		 if((cur_leaf_slot<max_slot)&&(cur_in_slot<max_slot) )

	 	{
			insert_leaf(mob_id, st, et);
			if (incont->in_node[cur_in_slot-1].et<et)
			{
			incont->in_node[cur_in_slot-1].et=et;
			}
		
		}//end else if(cur_leaf_slot<max_slot)



}//end  head !=null

 };  //end insert
void bptree::print()
{
cout<<endl<<"print"<<endl;
//for(int x=0; x<=cur_leaf_slot; x++)
//	cout <<endl<<"x=  "<<x<< "   leafcont.leaf_node[x].st=st   "<<leafcont.leaf_node[x].st<<"   leafcont.leaf_node[x].et   "<<leafcont.leaf_node[x].et<<"   leafcont.leaf_node[x].mob_id   "<<leafcont.leaf_node[x].mob_id<<endl;

}//end print


int main()          
{       
bptree tree(4,3);
tree.insert("m4", 1, 7);
tree.insert("m2", 2, 4);
 tree.insert("m1", 3, 12);
 tree.insert("m6", 4, 12);
 tree.insert("m0", 5, 12);
 tree.insert("m6", 6, 3);
 tree.insert("m9", 7, 20);
tree.print();
return 0; 
}///end main 
at firest,, idon't know how to thank u,,,,,
next:
i compile the file u send it
and in the bptree.h, i declare the objects like u recommend, and the bptree class become like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class bptree
    {
	public:
		
		int max_key;
		int max_slot;
		int cur_key;
		int cur_leaf_slot;
		int cur_in_slot;
		bptree * head;
		internal_container *incont;
		leaf_container *leafcont;
		void insert(string , int , int );
		void insert_leaf(string , int , int );
		void insert_internal(int , int );
		void newleafcont(int , int );
		void print();
		void newintcont();

		//initilization
		bptree(int mk,int ms)
		    {
			max_key = mk;
			max_slot=ms;
			cur_leaf_slot=0;
			cur_key= 0;
			cur_in_slot=0;
			head=NULL;
			
incont = new internal_container(max_key, max_slot);
leafcont=new leaf_container(max_slot);
		    }
	};//end class bptree



but the problem still in this function,,, we suppoze create new leafcontainer and then assign it's address to " incont->keys[cur_key] "

1
2
3
4
5
6
void bptree::newleafcont(int st,int et) 
	{
	  leafcont= new leaf_container(max_slot);
	incont->keys[cur_key] = (long )&leafcont;
         	cur_key++;
                 };



after insertion all the data ,,, if i print this values:

incont->keys[0] and incont->keys[1]

they give the same value !!!!!
now as leafcont is a pointer then you dont have to do this:
&leafcont

this will make it double pointer and when you de-reference it, it will give wrong results.

now do this instead:
1
2
3
4
5
6
void bptree::newleafcont(int st,int et) 
{
leafcont= new leaf_container(max_slot);
incont->keys[cur_key] = (long )leafcont;
cur_key++;
};

i think this should give correct results.
wooooooooooooooow

it is done with correct result

you are great wizard :)

thank you thank you thank you ......................................................................and thank you

:-)
oh.. great... i am happy.. :)
hello,,,

i applied what we did in function
void bptree::newleafcont(int st,int et)

to new function called newintcont
but it is not working !!!!!!1 i dont know why ??!!??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139

#include <iostream>
#include <ostream>
#include "bptree.h"
#include "bptree2.h"
using namespace std;
void bptree::newintcont()
{
/* i want to create new internalcontianer and make the head parameter point to it ,, the last head will be pointed by incont->keys[cur_key] ...........................  
incont->keys[cur_key] = (long ) temp;
*/
		cur_key=0;
		cur_in_slot=0;
		incont = new internal_container(max_key, max_slot);
		long *temp;
		temp=NULL;
		cout<<endl<<"incont   "<<(long)&incont <<"  head   "<<head<<"   temp  "<<temp<<endl;
		temp= head; // save the last address of head 
		cout<<"head   "<<head<<"   temp  "<<temp<<endl;
		
		head=(long * )&incont; // give the head new address
incont->keys[cur_key] = (long ) temp;  // save the temp value (which is the old address) in the key. 
		cout<<"head   "<<head<<"   temp  "<<temp<<"  incont->keys[cur_key]   "<<incont->keys[cur_key]<<endl;
	cur_key++;	
};

void bptree::newleafcont() 
	{
		
	leafcont= new leaf_container(max_slot);
cout<<"\n newleafcontainer at "<<(long )leafcont<<endl;
	incont->keys[cur_key] = (long )leafcont;
	cur_leaf_slot=0;
	cur_key++;

	};


void bptree::insert_internal(int st, int et)
{
                incont->in_node[cur_in_slot].st=st;
		incont->in_node[cur_in_slot].et=et;
                cur_in_slot++; 
};
void bptree::insert_leaf(string mob_id, int st, int et)

	{cout<<endl<<"  insert at  "<<st<<"   second    ";
		leafcont->leaf_node[cur_leaf_slot].st=st;
		leafcont->leaf_node[cur_leaf_slot].et=et;
		leafcont->leaf_node[cur_leaf_slot].mob_id=mob_id;
		cur_leaf_slot++;			 
	};
void bptree::insert(string mob_id, int st, int et)
 {

	if(head==NULL)
            {
		insert_internal(st, et);
		insert_leaf(mob_id, st, et);

        	incont->keys[cur_key] = (long )&leafcont;
		
head=(long * )&incont;
cout<<"head   "<<head<<endl;
		cur_key++;
					
	    }//end if
	else//head!=NULL
	   {	
			if(cur_leaf_slot<max_slot) // LEAF

		 	      {
				insert_leaf(mob_id, st, et);
				if (incont->in_node[cur_in_slot-1].et<et)
					incont->in_node[cur_in_slot-1].et=et;
				
		                }//end if(cur_leaf_slot<max_slot)

			else 
			if(cur_key<max_key)
		       {
			
			//cout<<"  new leaf container    l69 ";
			newleafcont();
			insert_internal(st, et);
			insert_leaf(mob_id, st, et);
	          	}//end (cur_key<max_key)

			else 
			{
				cout<<"\n insert new internal container"<<endl;
				newintcont();	
				newleafcont();

			insert_internal(st, et);
			insert_leaf(mob_id, st, et);	
			}//end last else

	}//end  head !=null

 };  //end insert
void bptree::print()
{
cout<<"\n print"<<endl;
cout<<endl<<"incont->keys[o] "<<incont->keys[0]<<"    (long )&leafcont   "<< (long )&leafcont; 
cout<<endl<<"   incont->keys[1]      "<<incont->keys[1]<<"    (long )&leafcont"<< (long )&leafcont; 
cout<<endl<<"incont->keys[2] "<<incont->keys[2]<<"    (long )&leafcont   "<< (long )&leafcont; 
cout<<endl<<"   incont->keys[3]      "<<incont->keys[3]<<"    (long )&leafcont"<< (long )&leafcont<<endl; 

//for(int x=0; x<=cur_leaf_slot; x++)
//	cout <<endl<<"x=  "<<x<< "   leafcont.leaf_node[x].st=st   "<<leafcont.leaf_node[x].st<<"   leafcont.leaf_node[x].et   "<<leafcont.leaf_node[x].et<<"   leafcont.leaf_node[x].mob_id   "<<leafcont.leaf_node[x].mob_id<<endl;

}//end print


int main()          
{       
bptree tree(3,2);
tree.insert("m4", 1, 7);
tree.insert("m2", 2, 4);
 tree.insert("m1", 3, 12);
 tree.insert("m6", 4, 12);
 tree.insert("m0", 5, 12);
 tree.insert("m6", 6, 3);
 tree.insert("m9", 7, 20);
tree.insert("m6", 8, 12);
 tree.insert("m0", 9, 12);
 tree.insert("m6", 10, 3);
 /*tree.insert("m9",11, 20);
tree.insert("m6", 12, 12);
 tree.insert("m0", 13, 12);
 tree.insert("m6", 14, 3);
 tree.insert("m9",15, 20);*/
//tree.print();

//delete *tree;
return 0; 
}///end main 



you havent posted the whole code, anyway looking at it i figured out the following things:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void bptree::newintcont()
{
/* i want to create new internalcontianer and make the head parameter point to it ,, the last head will be pointed by incont->keys[cur_key] ...........................  
incont->keys[cur_key] = (long ) temp;
*/
		cur_key=0;
		cur_in_slot=0;
		incont = new internal_container(max_key, max_slot); //is incont pointer??
		long *temp;
		temp=NULL;
		cout<<endl<<"incont   "<<(long)&incont <<"  head   "<<head<<"   temp  "<<temp<<endl;
//if incont is a pointer then why are you passing the address in cout??? pass just incont. ok?
		temp= head; // save the last address of head 
		cout<<"head   "<<head<<"   temp  "<<temp<<endl;
		
		head=(long * )&incont; // give the head new address
//again passing the address, why??
incont->keys[cur_key] = (long ) temp;  // save the temp value (which is the old address) in the key. 
		cout<<"head   "<<head<<"   temp  "<<temp<<"  incont->keys[cur_key]   "<<incont->keys[cur_key]<<endl;
	cur_key++;	
};


if there is still any problem, post the whole code. :)
see if you have this?
internal_container incont; then pass the address (&incont)
but if you have this:
internal_container *incont; then you should not pass the address because this will make it double pointer, i.e. **incont;
just passing incont will give the address so no need to do &incont. ok.
the cpp file,,,,
bp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <iostream>
#include <ostream>
#include "bptree.h"
#include "bptree2.h"
using namespace std;
void bptree::newintcont()
{
		cur_key=0;
		cur_in_slot=0;
		incont = new internal_container(max_key, max_slot);
		long *temp;
		temp=NULL;
		cout<<endl<<"incont   "<<(long)incont <<"  head   "<<head<<"   temp  "<<temp<<endl;
		temp= head;
		cout<<"head   "<<head<<"   temp  "<<temp<<endl;
		incont->keys[cur_key] = (long )temp;
		head=(long )incont; // error 
		cout<<"head   "<<head<<"   temp  "<<temp<<"  incont->keys[cur_key]   "<<incont->keys[cur_key]<<endl;
		};

void bptree::newleafcont() 
	{
		
	leafcont= new leaf_container(max_slot);
cout<<"\n newleafcontainer at "<<(long )leafcont<<endl;
	incont->keys[cur_key] = (long )leafcont;
	cur_leaf_slot=0;
	cur_key++;

	};


void bptree::insert_internal(int st, int et)
{
                incont->in_node[cur_in_slot].st=st;
		incont->in_node[cur_in_slot].et=et;
                cur_in_slot++; 
};
void bptree::insert_leaf(string mob_id, int st, int et)

	{cout<<endl<<"  insert at  "<<st<<"   second    ";
		leafcont->leaf_node[cur_leaf_slot].st=st;
		leafcont->leaf_node[cur_leaf_slot].et=et;
		leafcont->leaf_node[cur_leaf_slot].mob_id=mob_id;
		cur_leaf_slot++;			 
	};
void bptree::insert(string mob_id, int st, int et)
 {

	if(head==NULL)
            {
		insert_internal(st, et);
		insert_leaf(mob_id, st, et);

        	incont->keys[cur_key] = (long )&leafcont;
		
		head=(long )incont;//error 
		cout<<"head   "<<head<<endl;
		cur_key++;
					
	    }//end if
	else//head!=NULL
	   {	
			if(cur_leaf_slot<max_slot) // LEAF

		 	      {
				insert_leaf(mob_id, st, et);
				if (incont->in_node[cur_in_slot-1].et<et)
					incont->in_node[cur_in_slot-1].et=et;
				
		                }//end if(cur_leaf_slot<max_slot)

			else 
			if(cur_key<max_key)
		       {
			
			//cout<<"  new leaf container    l69 ";
			newleafcont();
			insert_internal(st, et);
			insert_leaf(mob_id, st, et);
	          	}//end (cur_key<max_key)

			else 
			{
				cout<<"\n insert new internal container"<<endl;
				newintcont();	
				newleafcont();

			insert_internal(st, et);
			insert_leaf(mob_id, st, et);	
			}//end last else

	}//end  head !=null

 };  //end insert
void bptree::print()
{
cout<<"\n print"<<endl;
cout<<endl<<"incont->keys[o] "<<incont->keys[0]<<"    (long )&leafcont   "<< (long )&leafcont; 
cout<<endl<<"   incont->keys[1]      "<<incont->keys[1]<<"    (long )&leafcont"<< (long )&leafcont; 
cout<<endl<<"incont->keys[2] "<<incont->keys[2]<<"    (long )&leafcont   "<< (long )&leafcont; 
cout<<endl<<"   incont->keys[3]      "<<incont->keys[3]<<"    (long )&leafcont"<< (long )&leafcont<<endl; 

//for(int x=0; x<=cur_leaf_slot; x++)
//	cout <<endl<<"x=  "<<x<< "   leafcont.leaf_node[x].st=st   "<<leafcont.leaf_node[x].st<<"   leafcont.leaf_node[x].et   "<<leafcont.leaf_node[x].et<<"   leafcont.leaf_node[x].mob_id   "<<leafcont.leaf_node[x].mob_id<<endl;

}//end print


int main()          
{       
bptree tree(3,2);
tree.insert("m4", 1, 7);
tree.insert("m2", 2, 4);
 tree.insert("m1", 3, 12);
 tree.insert("m6", 4, 12);
 tree.insert("m0", 5, 12);
 tree.insert("m6", 6, 3);
 tree.insert("m9", 7, 20);
tree.insert("m6", 8, 12);
 tree.insert("m0", 9, 12);
 tree.insert("m6", 10, 3);
 /*tree.insert("m9",11, 20);
tree.insert("m6", 12, 12);
 tree.insert("m0", 13, 12);
 tree.insert("m6", 14, 3);
 tree.insert("m9",15, 20);*/
//tree.print();

//delete *tree;
return 0; 
}///end main  

the headers file are:

bptree.h:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef B_PLUS_TREE

#define B_PLUS_TREE
#include <iostream>
#include <ostream>
#include <stdio.h>
#include <stdlib.h>
#include "bptree2.h"
using namespace std;
class bptree
    {
	public:
		
		int max_key;
		int max_slot;
		int cur_key;
		int cur_leaf_slot;
		int cur_in_slot;
		long * head;
		internal_container *incont;
		leaf_container *leafcont;
		void insert(string , int , int );
		void insert_leaf(string , int , int );
		void insert_internal(int , int );
		void newleafcont();
		void print();
		void newintcont();
bool f;

		//initilization
		bptree(int mk,int ms)
		    {
			max_key = mk;
			max_slot=ms;
			cur_leaf_slot=0;
			cur_key= 0;
			cur_in_slot=0;
			head=NULL;
			f=false;
incont = new internal_container(max_key, max_slot);
leafcont=new leaf_container(max_slot);
		    }
	};//end class bptree


#endif 



and bptree2.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef B_PLUS_TREE2

#define B_PLUS_TREE2

#include <iostream>
#include <ostream>
#include <stdio.h>
#include <stdlib.h>
#include "bptree.h"
using namespace std;

class internalslot
		{
		  public:
			int st;//start time
			int et;//end time
			
		};//end class internal 

	class internal_container
		{
		  public:

			internalslot *in_node;
			long *keys;
			internal_container *next_incont;

			internal_container(int mk, int ms)
				{
			     keys=new long [mk];
				in_node= new internalslot [ms];
				next_incont= NULL;
				 }

		};//end class internal_container
	
	class leafslot
		{
		  public:
			int st;
			int et;
			string mob_id;
			///leafslot *nextleaf;  // no pointer,, becUSE It is record [][][]

		};//end class leaf

	class leaf_container
		{
		  public:
			leafslot *leaf_node;
			leaf_container *next_leafcont;

			leaf_container( int ms)
		        {
				leaf_node=new leafslot[ms]; 
				next_leafcont=NULL;
			}

		};//end class leaf_container

 
//}; ///end class bptree	


#endif  

i declare in header file:

long * head;

i cpp file , when i want to give it a value:

head=(long )incont;

when i compile the code,, it give me this error :

bp.cpp: In member function ‘void bptree::newintcont()’:
bp.cpp:17: error: invalid conversion from ‘long int’ to ‘long int*’
bp.cpp: In member function ‘void bptree::insert(std::string, int, int)’:
bp.cpp:57: error: invalid conversion from ‘long int’ to ‘long int*’
make: *** [bp] Error 1




but,, if i use this

head=(long *) &incont;
no compilation errors ,,,,,
but the address not true ,,,,,


Last edited on
??????????????????
i sent all the files ....................


i declare in header file:

long * head;

i cpp file , when i want to give it a value:

head=(long )incont;

when i compile the code,, it give me this error :

bp.cpp: In member function ‘void bptree::newintcont()’:
bp.cpp:17: error: invalid conversion from ‘long int’ to ‘long int*’
bp.cpp: In member function ‘void bptree::insert(std::string, int, int)’:
bp.cpp:57: error: invalid conversion from ‘long int’ to ‘long int*’
make: *** [bp] Error 1




but,, if i use this

head=(long *) &incont;
no compilation errors ,,,,,
but the address not true ,,,,,
If I am not wrong, then in bp.cpp line 17 and 57 instead of writing
head = (long)incont;

just write
head = (long *) incont

Hope this helps
yes it is work,,
and the code become like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void bptree::newintcont()
{
		cur_key=0;
		cur_in_slot=0;
		incont = new internal_container(max_key, max_slot);
		long *temp;
		temp=NULL;
		cout<<endl<<"incont   "<<(long)incont <<"  head   "<<head<<"   temp  "<<temp<<endl;
		temp= head;
		cout<<"head   "<<head<<"   temp  "<<temp<<endl;
		incont->keys[cur_key] = (long )temp;   //why (long)incont
		head=(long *)incont;   //why (long *)incont
//what is the difference between the last two lines ?? why we use (long )count and in the next (long *)count ,,,, they are all of the same type==> long * .
		cout<<"head   "<<head<<"  long(head)  "<<long(head)<<"   temp  "<<temp<<"  incont->keys[cur_key]   "<<incont->keys[cur_key]<<endl;
		};


the output of this function:

1
2
3
4
incont   138551672  head   0x8422008   temp  0
head   0x8422008   temp  0x8422008
head   0x8422178  long(head)  138551672   temp  0x8422008  incont->keys[cur_key]   138551304


the bolded addresess have to be the same ,, but why i have to cast the value alwayse to ( long )
the are all of type long ????
so now the program is working fine??
Pages: 123