Very basic question.

Discussion in 'C++' started by ESOJAY, Jun 23, 2004.

  1. ESOJAY

    ESOJAY Guest

    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.

    --
    ESOJAY
     
    ESOJAY, Jun 23, 2004
    #1
    1. Advertising

  2. "ESOJAY" <> wrote in message
    news:cbbr8l$b3v$...
    > 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
     
    John Harrison, Jun 23, 2004
    #2
    1. Advertising

  3. ESOJAY

    ESOJAY Guest

    "John Harrison" <> wrote in message
    news:...
    >
    > "ESOJAY" <> wrote in message
    > news:cbbr8l$b3v$...
    > > 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


    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,

    --
    ESOJAY
     
    ESOJAY, Jun 23, 2004
    #3
  4. "ESOJAY" <> wrote in message
    news:cbc035$crs$...
    >
    > "John Harrison" <> wrote in message
    > news:...
    > >
    > > "ESOJAY" <> wrote in message
    > > news:cbbr8l$b3v$...
    > > > 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

    >
    > 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
     
    John Harrison, Jun 23, 2004
    #4
  5. ESOJAY

    Buster Guest

    ESOJAY wrote:
    > 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).

    --
    Regards,
    Buster.
     
    Buster, Jun 23, 2004
    #5
  6. ESOJAY

    David Harmon Guest

    On Wed, 23 Jun 2004 14:16:49 +0100 in comp.lang.c++, "ESOJAY"
    <> wrote,
    >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/
     
    David Harmon, Jun 23, 2004
    #6
    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. Raymond Arthur St. Marie II of III

    very Very VERY dumb Question About The new Set( ) 's

    Raymond Arthur St. Marie II of III, Jul 23, 2003, in forum: Python
    Replies:
    4
    Views:
    483
    Raymond Hettinger
    Jul 27, 2003
  2. aghazalp

    very very basic question

    aghazalp, Apr 2, 2006, in forum: Python
    Replies:
    6
    Views:
    346
    aghazalp
    Apr 2, 2006
  3. shanx__=|;-

    very very very long integer

    shanx__=|;-, Oct 16, 2004, in forum: C Programming
    Replies:
    19
    Views:
    1,629
    Merrill & Michele
    Oct 19, 2004
  4. Peter

    Very very very basic question

    Peter, Feb 8, 2005, in forum: C Programming
    Replies:
    14
    Views:
    517
    Dave Thompson
    Feb 14, 2005
  5. mdh

    A very **very** basic question

    mdh, Sep 25, 2008, in forum: C Programming
    Replies:
    57
    Views:
    1,237
    August Karlstrom
    Sep 26, 2008
Loading...

Share This Page