Help!!!!!!!!!!!!!!!!!1

This is a discussion on Help!!!!!!!!!!!!!!!!!1 within the C++ Programming forums, part of the General Programming Boards category; So here I am trying to make a little practice (very limited) string class when all of the sudden my ...

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Help!!!!!!!!!!!!!!!!!1

    So here I am trying to make a little practice (very limited) string class when all of the sudden my code won't compile, what a bi*ch huh? Well Please help.

    #include <iostream.h>
    #include <stdlib.h>
    #include <string.h>
    // here I was just starting my very limited string class and
    //all of the suddem THIS!!!!!! won't compile, help.
    //limited string class, just for practice
    class String
    {
    public:
    String();

    int Getlength(); //error
    int Get string();

    private:
    int length;
    int *string;
    };


    String::Get String() //error
    {
    return *string;
    }

    int main()
    {

    system("PAUSE");
    return 0;
    }

    //I was just beginning this little round of coding, as you can see I am really a newbie, and though that creating my own string class will really help a lot since it involves a lot of what C++ it's all about.


    //PS DON'T MAKE FUN OF ME, oh wait yes go ahead and laugh away
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    ok I got those fixed but now I can more errors (so this is how microsoft felt after releasing Win ME, tries to update 98 and ends up making the mess a bigger.)
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  3. #3
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    #include <iostream>
    #include <stdlib.h>
    #include <string.h>
    using namespace std;

    //limited string class, just for practice
    class String
    {
    public:
    String();

    int Getlength();
    int Getstring();

    private:
    int length;
    int *string;
    };


    String::Getstring()
    {
    return *string;
    }

    int main()
    {

    system("PAUSE");
    return 0;
    }

    /*I get this error "31 c:\docume~1\incogn~1\desktop\limite~1.cpp
    ANSI C++ forbids declaration `Getstring' with no type" */

    Please anybody out there?
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  4. #4
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    Code:
    String::Getstring() 
    { 
    return *string; 
    }
    is wrong. it should be this:

    Code:
    int* String::Getstring() 
    { 
    return string;  /* edited for error */
    }
    and the declararion should be this:
    int* Getstring();

    I usually use strings that are of type char but that's just me.
    Last edited by taylorguitarman; 01-27-2002 at 11:22 PM.

  5. #5
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Why should it have a (*) on it?
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  6. #6
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Oh because you're returning a reference of a string so it can be displayed? Am I close, well correct me.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  7. #7
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    Because that is the type you declared it as. The return value just has to match the type of whatever you are returning.

    Sorry I meant:
    Code:
    int* String::Getstring()
    {
     return string;
    }
    the variable doesn't have to have the * just the return type.
    it's late.

  8. #8
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Ok, I got it to compiler now......Thanks.......I'll keep on working on it tomorrow (man if you just read books and don't practice you're screwed, I am finding this the hard way, now I am having problems creating a simple string class).

    Code:
    const char *String::Getstring()
    {
    return  string;
    }
    So is this telling the computer to return the string as a constant reference? In turn returning the string?
    Last edited by incognito; 01-27-2002 at 11:27 PM.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  9. #9
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    Code:
    #include <iostream> 
    #include <stdlib.h> 
    #include <string.h> 
    using namespace std; 
    
    //limited string class, just for practice 
    class String 
    { 
    public: 
    String(); 
    
    int Getlength(); //error 
    char *Getstring(); 
    
    private: 
    int length; 
    char *string; 
    
    }; 
    
    
    char* String::Getstring() 
    { 
    return string; 
    } 
    
    int main() 
    { 
    
    system("PAUSE"); 
    return 0; 
    }
    this compiles. you're very close but still not getting a few concepts. keep it up though
    If a tree falls in the forest, and no one is around to see it, do the other trees make fun of it?

  10. #10
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Yeah thanks it compiled. Somehow my post telling you that I got it to compile didn't show up I guess because I see it but can't edit it.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help1
    By Joanna in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 11-03-2003, 12:13 AM
  2. Please Help!!!!1
    By GAMEPROJOE in forum C++ Programming
    Replies: 7
    Last Post: 07-14-2003, 03:23 AM
  3. Help!!!!!!!!!!!!!!!!!!1
    By redsoxj69 in forum C Programming
    Replies: 8
    Last Post: 04-25-2002, 02:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21