Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C++ & xCode Errors

  • 27-01-2011 10:38pm
    #1
    Registered Users, Registered Users 2 Posts: 8,004 ✭✭✭


    Hi Folks,

    Running the latest build of XCode and trying to write some C++.

    Program:
    bool isANumber(int check_prime, int max);
    
    int main () {
    	
        int check, max_N;
    
    	
        std::cout << "Enter Max N Value: ";
    	std::cin >> check;
    	
    	std::cout << check << " is the Check Value\n";
    	
    	if ( (isANumber(check, max_N) ) {
    
    //Do Something 
    }
    	
        return 0;
    }
    

    I'm very new to C++ but I've done C and Obj-C extensively. The problem is two fold:

    1) Why do I need std:: before the cin /cout commands? I'm using a command line tool project with the C++ option

    2) When I complile I get this error
    Undefined symbols:
    "isPrime(int, int)", referenced from:
    _main in main.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status

    Any pointers?


Comments

  • Registered Users, Registered Users 2 Posts: 894 ✭✭✭Dale Parish


    I havn't done C++ in years so I cannot help you with any question except for the use of std::
    Use this if you want to avoid doing that, add this to the top of your file:
    #include <iostream>
    using namespace std;
    


  • Registered Users, Registered Users 2 Posts: 981 ✭✭✭fasty


    Like in C, it's not enough to declare a function prototype, you need to provide an implementation of it.

    The std prefix is a namespace and as suggested above, you can say using namespace std; in your code to get around it.


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    ironclaw wrote: »
    Hi Folks,

    Running the latest build of XCode and trying to write some C++.

    Program:
    bool isANumber(int check_prime, int max);
    
    int main () {
    	
        int check, max_N;
    
    	
        std::cout << "Enter Max N Value: ";
    	std::cin >> check;
    	
    	std::cout << check << " is the Check Value\n";
    	
    	if ( (isANumber(check, max_N) ) {
    
    //Do Something 
    }
    	
        return 0;
    }
    

    I'm very new to C++ but I've done C and Obj-C extensively. The problem is two fold:

    1) Why do I need std:: before the cin /cout commands? I'm using a command line tool project with the C++ option

    2) When I complile I get this error



    Any pointers?
    1 ) As said previously, you must provide an implementation for a function. Computers and programming languages aren't psychic to automatically generate a function for you :)

    2 ) - Std is a namespace. It's away of avoiding conflicts. Similar groups of functions/classes are placed in a namespace. You can access these via their namespace.

    Putting
    using namespace std;
    
    will let the compiler know that you will be using functions such as cout and cin from this and allows you to implicitily mean you want the std namespace.

    However some people, including my place of work don't us the 'using' as it provides better means of avoiding conflicts. Instead use std::vector/cin etc. However this requires a bit more to write but still, shows exactly what functions you are using and from what namespace.


  • Registered Users, Registered Users 2 Posts: 8,004 ✭✭✭ironclaw


    Thanks folks. I got this sorted. With regards to the implementation of
    bool isANumber(int check_prime, int max)
    I forgot to include it in my snippet, it was declared and implemented correctly below.

    The errors disappeared, so maybe it was a error somewhere in xCode.

    Cheers for the help :)


Advertisement