Thread: Help me pls

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    17

    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.

  2. #2
    Shadow12345
    Guest
    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)

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    17
    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.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You've declared both sections of your class as private. One should be public.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    17
    LOL Thank you now I feel so stupid so obvious. Gah I look for that forever. Tks alot I ll go fix it now.

  6. #6
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    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;
    };
    Couldn't think of anything interesting, cool or funny - sorry.

  7. #7
    Registered User
    Join Date
    Sep 2002
    Posts
    17
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic port scanner code .. pls help ???
    By intruder in forum C Programming
    Replies: 18
    Last Post: 03-13-2003, 08:47 AM
  2. i dont know what to do. pls. help!!!!
    By Unregistered in forum C++ Programming
    Replies: 14
    Last Post: 03-14-2002, 03:24 PM
  3. help me pls..... :(
    By mocha_frap024 in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2002, 10:46 AM
  4. pls help me!!
    By hanseler in forum C++ Programming
    Replies: 1
    Last Post: 12-05-2001, 08:46 PM
  5. Pls Help Me In This Question!!!
    By Joanna in forum Windows Programming
    Replies: 1
    Last Post: 10-20-2001, 02:05 PM