Article View: att.lang.c++
Article #76Pointers To A Class
From: New C Programmer
Date: Tue, 28 Mar 2000 00:00
Date: Tue, 28 Mar 2000 00:00
158 lines
4012 bytes
4012 bytes
I am having a problem with passing pointers to a class.
I have a class called stack that works fine but when I try to pass a pointer
to an instance
of the class it gives me problems.
I need to know how to get to the methods of the object when I get it to the
function and
perhaps how to pass it.
this is the sending function,
below it is a snipit of the recieving function.
#include "scj_arr.h"
#include "stack.h"
#include "ass_out.h"
#include<iostream.h>
#include<stdlib.h>
#include<ctype.h>
#include<fstream.h>
#define MAX 50
// Function Prototypes
int file_to_stack(stack *my_stack1, stack *my_stack2);
int order_stack(stack *my_stack1, stack *my_stack2);
void init_array(const char init_val, char array[], int arr_size);
int process_command();
int check_op(char c);
file://int out_to_file(stack my_stack1, stack my_stack2);
void main()
{
int test=0;
int quit=0;
static stack my_stack1;
static stack my_stack2;
stack *ptr_to_stack1;
stack *ptr_to_stack2;
ptr_to_stack1 = &my_stack1;
ptr_to_stack2 = &my_stack2;
int finished = 0;
cout << "\nAssembly Compiler Program\n";
while (!quit)
{
test = file_to_stack(ptr_to_stack1, ptr_to_stack2);//stack 2 is corrected
test = order_stack(ptr_to_stack1, ptr_to_stack2); file://stack 1 is
corrected
test = out_to_file(ptr_to_stack1, ptr_to_stack2); file://use stack 1
cout << endl;
cout << endl;
my_stack1.st_clear();
cout << "All Done? 1=YES 0=NO \n";
cin >> quit;
}
}
file://here is one of the recieving functions
int file_to_stack(stack *my_stack1, stack *my_stack2)
{
char c;
char c1;
int count2=0;
int count3=0;
int pass_fail = 0;
FILE *stream;
int numread;
char item;
char element[MAX];
char temp_element[MAX];
char temp_element2[MAX];
char filename_in[80];
int count = 0;
int count1 = 0;
init_array(NULL, element, MAX);
init_array(NULL, temp_element, MAX);
init_array(NULL, temp_element2, MAX);
cout << "What is the name of the file you want to open?";
cout << endl;
cin >> filename_in;
stream=fopen(filename_in, "rb");// open for read binary
do /*create a stack of arrays of equations*/
{
numread = fread(&item, sizeof(char),1,stream);
if ((isalnum(item)) || (ispunct(item)) && (isprint(item)))
{
element[count] = item;
++count;
if ((item==';') && (isprint(item)) && (item>0))
{
strcpy(temp_element,element);
for (count2=0; count2<count; count2++)
{
c = element[count2];
c1 = element[count2+1];
temp_element[count3]=c;
temp_element2[0]=c1;
++count3;
if (check_op(c1))
{
my_stack1.st_put( temp_element );
my_stack1.st_put( temp_element2 );
init_array(NULL, temp_element, MAX);
init_array(NULL, temp_element2, MAX);
count3 = 0;
count2++;
}
}
cout << element;
cout << "\n";
init_array(NULL, element, MAX);
count = 0;
item = NULL;
}
}
} while (numread>0);
cout << endl;
my_stack1.st_dump();
fclose(stream);
return pass_fail;
}
I get this sort of error "left of .st_put requires class/struct/union type"
I understand
that I have only the pointer to the stack in the function but I cannot seem
to dereferance
the pointer. I would appreciate any help.
Regards,
New C++ Programmer
Technical Details
Message-ID:
<8br6t6$3dc$1@bob.news.rcn.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d4ba,62524d9860e4dcd5,start X-Google-Attributes: gid10d4ba,public From: "New C Programmer" <s_joanis@siebe-ene.com> Subject: Pointers To A Class Date: 2000/03/28 Message-ID: <8br6t6$3dc$1@bob.news.rcn.net> X-Deja-AN: 603575291 X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 X-Complaints-To: abuse@rcn.com X-Trace: VOAU8lRKFbgOpkrX+55XYoipbw+63zUBTrvNO1AVoJg= Organization: Siebe-ENE X-MSMail-Priority: Normal Reply-To: "New C Programmer" <s_joanis@siebe-ene.com> NNTP-Posting-Date: 28 Mar 2000 21:06:46 GMT Newsgroups: att.lang.c++