link list array

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;
class Network
{
// private function to constructe the nodes with a left and right childed
private:

struct node
{


node* left;
node* mid;
node* right;
char data;
};
node* root;
// public function for the the program
public:
char *Nodes ;
Network()
{
root = NULL;
}

char Link(char,char);



node* Network::Order(char* temp){


cout << "Order:" << sizeof(temp);

node* store;
store = new node[sizeof(temp)];



};
};


char Network::Link(char temp, char temp1){

};




// Smaller elements go left
// larger elements go right



/*
*
*/
int main() {

Network object;
char p[11];
p[0] = 'a';
p[1] = 'b';

cout << "p:" << sizeof(p);
object.Order(p);
return 0;
}




output: p:11 Order:4

question: why is Order printing out 4 , should be printing out 11
I might be wrong on this, but I believe in main, you're printing out the size of the array, but in your member class, you're printing out the size of the pointer, which is char in this case, so you get 4 back. I'm a little rough on it, but believe it's working that way for a reason. Why are you using a pointer instead of an array anyways?

Edit: I believe you might be able to dereference temp to get the size of the array.
Last edited on
Topic archived. No new replies allowed.