Undefined reference in G++.

Discussion in 'C++' started by Andrix, Jun 22, 2006.

  1. Andrix

    Andrix Guest

    Hi!

    I'm writing a class that have a static function

    class Servicios {
    public:
    static String * intToString(int value);
    };

    an another class String that I write to.

    namespace DataTypes {
    class String {
    ......
    };

    ostream& operator<< (ostream&, const String &);
    istream& operator>>(istream&, String &)
    }

    the class String has two iostream functions implemented outside the
    class.

    I have to a main.cc that has something like this:

    int main() {
    String * str = Servicios::intToString(100);
    cout << str;

    }

    but when I do a make from all this, I have the error

    In main.cc: undefined reference to .............function
    ostream....(....)


    Questions:
    what is undefined reference? when ocurr? how to solve this problem?

    thanks a lot.

    Andrix.
    Andrix, Jun 22, 2006
    #1
    1. Advertising

  2. Andrix

    red floyd Guest

    Andrix wrote:
    > Hi!
    >
    > I'm writing a class that have a static function
    >
    > class Servicios {
    > public:
    > static String * intToString(int value);
    > };
    >
    > an another class String that I write to.
    >
    > namespace DataTypes {
    > class String {
    > ......
    > };
    >
    > ostream& operator<< (ostream&, const String &);
    > istream& operator>>(istream&, String &)
    > }
    >
    > the class String has two iostream functions implemented outside the
    > class.
    >
    > I have to a main.cc that has something like this:
    >
    > int main() {
    > String * str = Servicios::intToString(100);
    > cout << str;
    >
    > }
    >
    > but when I do a make from all this, I have the error
    >
    > In main.cc: undefined reference to .............function
    > ostream....(....)
    >
    >
    > Questions:
    > what is undefined reference? when ocurr? how to solve this problem?
    >


    You're trying to invoke operator<<(ostream&, const String *). It's not
    defined anywhere. Why are you returing a String* from intToString,
    rather than a String?
    red floyd, Jun 22, 2006
    #2
    1. Advertising

  3. * Andrix:
    >
    > I'm writing a class that have a static function
    >
    > class Servicios {
    > public:
    > static String * intToString(int value);
    > };


    Who is responsible for deallocating that String, and how?

    Better use std::string.


    > an another class String that I write to.
    >
    > namespace DataTypes {
    > class String {
    > ......
    > };
    >
    > ostream& operator<< (ostream&, const String &);
    > istream& operator>>(istream&, String &)
    > }
    >
    > the class String has two iostream functions implemented outside the
    > class.
    >
    > I have to a main.cc that has something like this:
    >
    > int main() {
    > String * str = Servicios::intToString(100);
    > cout << str;


    That will output a pointer value.


    > }
    >
    > but when I do a make from all this, I have the error
    >
    > In main.cc: undefined reference to .............function
    > ostream....(....)
    >
    >
    > Questions:
    > what is undefined reference?


    That your program is using something that is not defined.


    > when ocurr?


    You haven't shown the relevant code.


    > how to solve this problem?


    Define whatever is missing.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
    Alf P. Steinbach, Jun 22, 2006
    #3
  4. * red floyd:
    > Andrix wrote:
    >> Hi!
    >>
    >> I'm writing a class that have a static function
    >>
    >> class Servicios {
    >> public:
    >> static String * intToString(int value);
    >> };
    >>
    >> an another class String that I write to.
    >>
    >> namespace DataTypes {
    >> class String {
    >> ......
    >> };
    >>
    >> ostream& operator<< (ostream&, const String &);
    >> istream& operator>>(istream&, String &)
    >> }
    >>
    >> the class String has two iostream functions implemented outside the
    >> class.
    >>
    >> I have to a main.cc that has something like this:
    >>
    >> int main() {
    >> String * str = Servicios::intToString(100);
    >> cout << str;
    >>
    >> }
    >>
    >> but when I do a make from all this, I have the error
    >>
    >> In main.cc: undefined reference to .............function
    >> ostream....(....)
    >>
    >>
    >> Questions:
    >> what is undefined reference? when ocurr? how to solve this problem?
    >>

    >
    > You're trying to invoke operator<<(ostream&, const String *).


    Output of void* is defined. Nothing in the code shown indicates that
    operator<<(ostream&, const String*) is invoked. We don't know what the
    missing function is because the OP has replaced all info with periods.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
    Alf P. Steinbach, Jun 22, 2006
    #4
  5. Andrix

    red floyd Guest

    Alf P. Steinbach wrote:
    > * red floyd:


    >>
    >> You're trying to invoke operator<<(ostream&, const String *).

    >
    > Output of void* is defined. Nothing in the code shown indicates that
    > operator<<(ostream&, const String*) is invoked. We don't know what the
    > missing function is because the OP has replaced all info with periods.
    >


    Crud. Forgot about the automatic conversion to void*.
    red floyd, Jun 22, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Felipe
    Replies:
    3
    Views:
    445
    Felipe
    Jul 16, 2004
  2. Lu
    Replies:
    1
    Views:
    570
    Roel Schroeven
    Jul 10, 2003
  3. Mantorok Redgormor
    Replies:
    70
    Views:
    1,753
    Dan Pop
    Feb 17, 2004
  4. VK
    Replies:
    45
    Views:
    591
    Dr John Stockton
    Sep 12, 2006
  5. -Lost
    Replies:
    13
    Views:
    370
    Richard Cornford
    Jan 31, 2007
Loading...

Share This Page