Very basic question.

E

ESOJAY

My native language is c, but I have the unpleasant task of porting a C++
code from SGI MIPS to Linux Opteron, I have no help from the author of the
code.

One of several problems is that my g++ (3.3.3) compiler balks at expressions
like <int>: for example if Scan is a well defined object, the compiler balks
at Scan<int> ::~Scan; the error message is 'undefined reference to
Scan<int>'. Is <int> a cast operator? What can be done to avoid the error
message?

Thanks in advance.
 
J

John Harrison

ESOJAY said:
My native language is c, but I have the unpleasant task of porting a C++
code from SGI MIPS to Linux Opteron, I have no help from the author of the
code.

One of several problems is that my g++ (3.3.3) compiler balks at expressions
like <int>: for example if Scan is a well defined object, the compiler balks
at Scan<int> ::~Scan; the error message is 'undefined reference to
Scan<int>'. Is <int> a cast operator? What can be done to avoid the error
message?

Thanks in advance.

Looks like a template parameter, but who can say unless you post at the very
least complete line of code.

POST MORE CODE.

john
 
E

ESOJAY

John Harrison said:
Looks like a template parameter, but who can say unless you post at the very
least complete line of code.

POST MORE CODE.

john

The code looks like:

#include <file1>
#include <file2>
#include <file3>
using namespace std;

#include "file4"
#include "file5"

typedef vector<double> Var1;
typedef double Var2;

template <class T>
class func {

public:
func (vector<int *> Var3, int *Var4, int *Var5 = NULL) ;
func (vector<Var1> Var6) ;
func (vector<Var2>& Var6) ;
func (func<T> &m) ;
~func(void);
...........................
void func2(bool b) ;

protected:
.....................
};

The offending line is:
func<int>::func2(bool).
Linker error is undefined reference to func<int>::func2(bool).

Thanks,
 
J

John Harrison

ESOJAY said:
The code looks like:

#include <file1>
#include <file2>
#include <file3>
using namespace std;

#include "file4"
#include "file5"

typedef vector<double> Var1;
typedef double Var2;

template <class T>
class func {

public:
func (vector<int *> Var3, int *Var4, int *Var5 = NULL) ;
func (vector<Var1> Var6) ;
func (vector<Var2>& Var6) ;
func (func<T> &m) ;
~func(void);
...........................
void func2(bool b) ;

protected:
.....................
};

The offending line is:
func<int>::func2(bool).
Linker error is undefined reference to func<int>::func2(bool).

Thanks,

A linker error means that you've failed to define the entity named. In this
case you've failed to give a definition for the method func2, in the class
template func<T>, in the case when T equals int.

Now there is no such definition in the code you've posted but maybe the
definition is somewhere else in your code. Do you see a function looking
something like this

template <class T>
void func<T>::func2(bool ...)
{
...
}

somewhere in your code? Its because that hasn't been included in your code
or has been included but not in the right place that you are getting linker
errors.

It would also be worth looking around and seeing where the method func2 is
actually being called.

john
 
B

Buster

ESOJAY said:
My native language is c, but I have the unpleasant task of porting a C++
code from SGI MIPS to Linux Opteron, I have no help from the author of the
code.

One of several problems is that my g++ (3.3.3) compiler balks at expressions
like <int>: for example if Scan is a well defined object, the compiler balks
at Scan<int> ::~Scan; the error message is 'undefined reference to
Scan<int>'. Is <int> a cast operator? What can be done to avoid the error
message?

Do you know on what compiler(s) the original code was compiled? Template
instantiation can be handled in several different ways. See the GCC
TexInfo manual, under 'C++ Extensions --> Template Instantiation', or
the comp.lang.c++ FAQ (search the web for that).
 
D

David Harmon

On Wed, 23 Jun 2004 14:16:49 +0100 in comp.lang.c++, "ESOJAY"
The offending line is:
func<int>::func2(bool).
Linker error is undefined reference to func<int>::func2(bool).

Please refer to these topics in Marshall Cline's C++ FAQ and see if they
shed any light on the problem:

[34.12] Why can't I separate the definition of my templates class from
it's declaration and put it inside a .cpp file?

[34.13] How can I avoid linker errors with my template functions?

You can get the FAQ at: http://www.parashift.com/c++-faq-lite/
 

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

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top