Undefined reference in G++.

A

Andrix

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.
 
R

red floyd

Andrix said:
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?
 
A

Alf P. Steinbach

* 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

Alf P. Steinbach

* 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.
 
R

red floyd

Alf said:
* red floyd:

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*.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top