Okay so i've just really started getting into pointers cause i've been working with linked lists, double-linked lists, and (im now trying) binary trees. Here's my problem:
Here's my code:Quote:
c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\binary tree 2\binary tree 2\main.cpp(105) : error C2440: '=' : cannot convert from 'int *__w64 ' to 'int'
There is no context in which this conversion is possible
What am i doing wrong? My Learn C++ in 21 Days book says that's how you set the pointer to the address of something. The fact that it's an array changes things maybe?Code:#include <iostream>
using namespace std;
//Node Structure
struct node
{
int data; //Data of the Node (int)
node *parent; //Pointer to the Parent Node
node *cLeft; //Pointer to the child node on the left
node *cRight; //Pointer to the child node on the right
};
//Global Variables
node *root;
node *current;
//Function Prototypes
void createTree(int numbers[]); //Creates the Tree
void addPly(); //Used by createTree, adds another ply/level to the tree
void displayTree(); //Displays the Tree
void searchTree(int number); //Searches the tree for a certain number
void sortNumbers(int numbers[], int *pNum[]); //Sorts an Array of numbers from Lowest to Highest
bool assignPointersArray(int numbers[], int *pNum[]);
int main()
{
root = new node; //Clear out memory for the Root node
int numbers[10]; //Array of numbers to be represented by the tree
int *pNum[10]; //Array of Pointers to the array of numbers
if(assignPointersArray(numbers, pNum) == false)//Function which assigns pointers to the numbers
{
return 1;
//Fatal Error
}
//Get Numbers
cout<<"Please Enter 10 Numbers..."<<endl;
for(int g=0; g<10; g++)
{
cout<<"Element "<<(g+1)<<": ";
cin>>numbers[g];
}
sortNumbers(numbers, pNum);
cin.ignore();
createTree(numbers);
displayTree();
cin.ignore();
return 0;
}
void createTree(int numbers[])
{
//Create Tree Function
}
void sortNumbers(int numbers[], int *pNum[])
{
//Sort Number Array Function - LO-HI
int temp1, temp2;
for(int i=0; i<(sizeof(numbers)); i++)
{
for(int s=0; s<(sizeof(numbers)); s++)
{
if(numbers[s] > numbers[s+1])
{
temp1 = numbers[s];
temp2 = numbers[s+1];
numbers[s] = temp2;
numbers[s+1] = temp1;
}else if(numbers[s] < numbers[s+1])
{
//Nothing - Stay the Same
}else if(numbers[s] == numbers[s+1])
{
//Nothing - Stay the Same
}else{
//Nothing - Stay the Same
}
}
}
//Display Array
for(int j=0; j<(sizeof(numbers)); j++)
{
cout<<"Element "<<(j+1)<<" Equals: "<<numbers[j]<<endl;
}
}
void displayTree()
{
//Display Tree Function
}
bool assignPointersArray(int numbers[], int *pNum)
{
//Assign Pointers to Array Elements Function
if(sizeof(numbers) != sizeof(pNum))
return false;
else{
for(int i=0; i<(sizeof(numbers)); i++)
{
pNum[i] = &numbers[i];
}
return true;
}
}
Thanks for any help you can give!