Thread: What is Wrong?

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    66

    What is Wrong?

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int plus(const int& val1,const int& val2);
    double plus(const double& val1,const double& val2);
    string plus(const string& val1,const string& val2);
    
    int main()
    {
        int n = plus(3,4);    // error here
        double d = plus(3.2,4.2);
        string s = plus("he","llo");
        string s1 = "aaa";
        string s2 = "bbb";
        string s3 = plus(s1,s2);
        
        cout << "n = " << n;
             << "d = " << d;
             << "s = " << s;
             << "s1 = " << s1;
             << "s2 = " << s2;
             << "s3 = " << s3
             << endl
             << endl;
        
        system("PAUSE");
        return 0;
    }
    
    int plus(const int& val1,const int& val2)
    {
        return val1 + val2
    }
    
    double plus(const double& val1,const double& val2)
    {
        return val1 + val2
    }
    
    string plus(const string& val1,const string& val2)
    {
        return val1 + val2
    }
    It says 'use' on the line int n = plus(3,4); .I dunno why though. Is it my compiler's (Dev C++) problem once again?
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    You have semicolon issues. There are semicolons where none should be and none where semicolons should be. To be more specific:
    Code:
        cout << "n = " << n;
             << "d = " << d;
             << "s = " << s;
             << "s1 = " << s1;
             << "s2 = " << s2;
             << "s3 = " << s3
             << endl
             << endl;
    A semicolon ends a statement, since the next << continues a statement, your compiler feels that continuing an ending is rather counterintuitive.

    >return val1 + val2
    A return statement should definitely be ended since the next token is a closing brace, and compilers don't like to see those in an expression for some reason.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    66
    Originally posted by Prelude
    You have semicolon issues. There are semicolons where none should be and none where semicolons should be. To be more specific:
    Code:
        cout << "n = " << n;
             << "d = " << d;
             << "s = " << s;
             << "s1 = " << s1;
             << "s2 = " << s2;
             << "s3 = " << s3
             << endl
             << endl;
    A semicolon ends a statement, since the next << continues a statement, your compiler feels that continuing an ending is rather counterintuitive.

    >return val1 + val2
    A return statement should definitely be ended since the next token is a closing brace, and compilers don't like to see those in an expression for some reason.
    Ahh, thx. I just saw them too. But i still can't compile it....
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >But i still can't compile it....
    I suppose Dev-C++ doesn't like your use of the identifier plus. It conflicts with the STL function object of the same name.
    My best code is written with the delete key.

  5. #5
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Originally posted by Cris987
    But i still can't compile it....
    You're going to have to be a lot more specific. What is your new error? On what line is it? What does you modified code now look like?

    Help us to help you.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  6. #6
    Registered User
    Join Date
    Nov 2003
    Posts
    66
    Originally posted by joshdick
    You're going to have to be a lot more specific. What is your new error? On what line is it? What does you modified code now look like?

    Help us to help you.
    It's the same error on the same line:

    int n = plus(3,4);


    the error is 'use'
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

  7. #7
    Registered User
    Join Date
    Nov 2003
    Posts
    66
    Originally posted by Prelude
    >But i still can't compile it....
    I suppose Dev-C++ doesn't like your use of the identifier plus. It conflicts with the STL function object of the same name.
    You're right...I got it.
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM