Thread: (Rookie) Creating a void Function error

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    4

    Unhappy (Rookie) Creating a void Function error

    So im using Dev C++, and im reading a book about C++, im triying to create a void function = no return function.
    But when I try to compile it a get several errors such as

    variable or field `PrintName' declared void

    `string' was not declared in this scope

    Con you guys help me please?
    Heres the screen cap
    http://img855.imageshack.us/img855/9549/asdasdasdss.jpg
    Attached Images Attached Images (Rookie) Creating a void Function error-asdasdasdss-jpg 
    Last edited by Joel Hernández; 12-17-2012 at 09:22 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You probably should move that using directive to just before that function definition. Also, note that you are missing a semi-colon and closing brace for your main function.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2012
    Posts
    4
    Allright so i Tried this way
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <string>
    using namespace std;
    void PrintName(string frist,string last)
    {
         string fullname = first + " " + last;
         cout << fullname << endl;
         }
    
    
     
     
    int main(int argc, char *argv[])
    {
        PrintName("Thomas","Jefferson")
    }
        system("PAUSE");
        return EXIT_SUCCESS;
    and still have multiple errors
    Heres the link for BIG img
    http://img855.imageshack.us/img855/9549/asdasdasdss.jpg
    Attached Images Attached Images (Rookie) Creating a void Function error-asdasdasds-jpg 
    Last edited by Joel Hernández; 12-17-2012 at 09:15 PM.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Post the error messages, not a screen shot. What do you think the error messages mean?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Dec 2012
    Posts
    4
    Quote Originally Posted by laserlight View Post
    Post the error messages, not a screen shot. What do you think the error messages mean?
    In the screenshot you can see the multiple errors listed... , one of them says that "first" its not declared , but I allready did, I declared string first, string last ...

  6. #6
    Registered User
    Join Date
    Dec 2012
    Posts
    4
    Found the error, typing mistake. LOL

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Joel Hernández
    In the screenshot you can see the multiple errors listed
    Certainly, but the idea here is for you to get a closer look at the error messages when copying them from your IDE's window and then pasting them here, nicely formatted with line numbers. Furthermore, it is easier to read as text than as an image.

    Quote Originally Posted by Joel Hernández
    one of them says that "first" its not declared , but I allready did, I declared string first, string last ...
    Quote Originally Posted by Joel Hernández
    Found the error, typing mistake. LOL
    Good. What about the others?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by Joel Hernández View Post
    Found the error, typing mistake. LOL
    What, you mean I'm too late to say "FRIST"?!

    The last two lines of code need to be inside the main function. At the moment they are floating off into space from no-mans-land.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error: invalid conversion from 'const void*' to 'void*'
    By Wahidin Wahid in forum C++ Programming
    Replies: 10
    Last Post: 04-17-2012, 02:17 AM
  2. error invalid conversion from ‘const void*’ to ‘void*’
    By Wahidin Wahid in forum C Programming
    Replies: 3
    Last Post: 03-27-2012, 08:18 PM
  3. an uber-simple array/function question for a c rookie!
    By variable83 in forum C Programming
    Replies: 13
    Last Post: 12-06-2009, 01:24 PM
  4. void function that builds but error when trying to run
    By romeoz in forum C++ Programming
    Replies: 7
    Last Post: 07-18-2003, 06:52 PM
  5. Replies: 4
    Last Post: 01-02-2002, 10:57 PM