-
Help me pls
I m a student at a local college. New to C++. My latest program has me a bit baffled. I wrote the class file, and implimentation file. When I wrote the main I compiled it and got errors that said function not available in function main. The functions it is talking about are the ones in my implimentation file. It does this for every one of my functions. I can post code if needed but simply being pointed in the right direction on where to look would be good enough I think. Tks for any help you all give.
-
mmm I have an idea of what your problem might be but when you post on these forums with a coding problem you need to post the code as well. There could be a bazillion reasons for your problem and unless you show us what you have written there honestly isn't a whole lot we can do unless it is one of the most common problems.
When you do enter code put:
[ code ]
at the top of your code and
[ /code ] at the bottom of your code (each WITHOUT spaces)
-
Code:
#include <iostream>
const int maxsize = 50;
class stackchar
{
private: stackchar();
void enqueue(char val);
char front();
void dequeue();
bool isfull();
bool isempty();
bool isempty2();
bool isfull2();
void push(char newchar);
void pop();
char topelement();
private:
int frontelement;
int rear;
char s1[maxsize];
char s2[maxsize];
char s3[maxsize];
int top;
int vecsize;
};
--------------------------------------------------------------------------------
#include "s2p1.h"
#include <iostream.h>
stackchar::stackchar()
{
rear = frontelement = 0;
}
bool stackchar::isempty()
{
return(rear == frontelement);
}
bool stackchar::isfull()
{
return(rear+1%vecsize==frontelement);
}
void stackchar::enqueue(char val)
{
rear =(val)%vecsize;
}
char stackchar::front()
{
return s1[frontelement+1%vecsize];
}
void stackchar::dequeue()
{
frontelement=(frontelement+1)%vecsize;
}
bool stackchar::isfull2()
{
return(top==maxsize);
}
bool stackchar::isempty2()
{
return(top==-1);
}
void stackchar::push(char newchar)
{
s2[++top]=newchar;
}
char stackchar::topelement()
{
return s2[top];
}
void stackchar::pop()
{
top--;
}
-------------------------------------------------------------------
#include"s2p1.cpp"
#include<iostream.h>
#include<fstream.h>
#include<string.h>
int main()
{
stackchar s1;
stackchar s2;
stackchar s3;
int frontelement;
int rear;
cout<<"Please enter a sentence to be tested $ to exit: ";
cin.get(s1.enqueue());
s1.pop();
return 0;
}
This is a very raw program dont laugh there is alot to add to it but this problem popped up early.
-
You've declared both sections of your class as private. One should be public.
-
LOL Thank you now I feel so stupid so obvious. Gah I look for that forever. Tks alot I ll go fix it now.
-
Try changing the #include #include"s2p1.cpp" to #include "s2p1.h" - that is where the stack declaration is, you should never really need to include a .cpp file. A possible cause is that your class defines everything as private, even the constructors whihc should be public.
Code:
class stackchar
{
public: stackchar();
void enqueue(char val);
char front();
void dequeue();
bool isfull();
bool isempty();
bool isempty2();
bool isfull2();
void push(char newchar);
void pop();
char topelement();
private:
int frontelement;
int rear;
char s1[maxsize];
char s2[maxsize];
char s3[maxsize];
int top;
int vecsize;
};
-
yep changing to public did it. Still got errors but expected them and they are nothing I ve not seen before. Tks for the help.