templated code not able to call correct constructor

K

Keith Halligan

I'm switching from the HP-UX compiler aCC 5.55 to aCC 6.13 and I get
the following error:

"templateptr.h", line 20: error #2289: no instance
of constructor "defclass::base::base" matches the
argument list
argument types are: (obj *)
: defclass::base(p)
^
detected during instantiation of
"templateptr<T>::templateptr(T *) [with
T=obj]" at line 50 of
"starter.h"

Since an obj is derived from a defclass, I don't see the problem.

The line I'm using to compile is:

/opt/bin/aCC -o main main.cxx


I'm also getting similar issues on a linux box with GCC 3.4.6 and it
wasn't an issue with 3.2.3.

I was thinking it might be the new two name lookup in the new compiler
but passing +dep_name and +nodep_name switches are making no
difference.

Does anyone have any ideas on it?


-----------------
main.cxx
-----------------
#include <iostream>
#include "starter.h"

int main(void)
{
starter s;

return 0;
}

--------------
starter.h
--------------
#include "templateptr.h"

class obj;

typedef templateptr<obj> obj_ptr;

class starter
{
public:
starter() {}
~starter() {}

obj_ptr p;

};

--------------------
template_ptr.h
--------------------
#include "itrefcounted.h"

template <class T>

class templateptr
: public defclass::base
{
public:
inline templateptr(T* p = 0);

};


template <class T>
inline
templateptr<T>::templateptr(T* p)
: defclass::base(p)
{
}


-------------
defclass.h
-------------


class defclass
{
public:


class base
{
public:
// base (base b);
base (defclass* p = 0);

defclass *m_ref;

};


friend class base;

};


---------------
defclass.cxx
---------------
#include "defclass.h"

itrefcounted::base(defclass *p)
: m_ref(p)
{
}


----------
obj.h
---------
#include "defclass.h"


class obj
: public defclass
{
public:
obj() {}
~obj() {}

};
 
V

Victor Bazarov

Keith said:
I'm switching from the HP-UX compiler aCC 5.55 to aCC 6.13 and I get
the following error:

"templateptr.h", line 20: error #2289: no instance
of constructor "defclass::base::base" matches the
argument list
argument types are: (obj *)
: defclass::base(p)
^
detected during instantiation of
"templateptr<T>::templateptr(T *) [with
T=obj]" at line 50 of
"starter.h"

Since an obj is derived from a defclass, I don't see the problem.

The line I'm using to compile is:

/opt/bin/aCC -o main main.cxx


I'm also getting similar issues on a linux box with GCC 3.4.6 and it
wasn't an issue with 3.2.3.

I was thinking it might be the new two name lookup in the new compiler
but passing +dep_name and +nodep_name switches are making no
difference.

Does anyone have any ideas on it?

Please collect all the code in _one_ module, and post it *again*.
[...disconnected and incomplete code snipped...]

V
 
K

Keith Halligan

Keith said:
I'm switching from the HP-UX compiler aCC 5.55 to aCC 6.13 and I get
the following error:
"templateptr.h", line 20: error #2289: no instance
of constructor "defclass::base::base" matches the
argument list
argument types are: (obj *)
: defclass::base(p)
^
detected during instantiation of
"templateptr<T>::templateptr(T *) [with
T=obj]" at line 50 of
"starter.h"
Since an obj is derived from a defclass, I don't see the problem.
The line I'm using to compile is:
/opt/bin/aCC -o main main.cxx
I'm also getting similar issues on a linux box with GCC 3.4.6 and it
wasn't an issue with 3.2.3.
I was thinking it might be the new two name lookup in the new compiler
but passing +dep_name and +nodep_name switches are making no
difference.
Does anyone have any ideas on it?

Please collect all the code in _one_ module, and post it *again*.
[...disconnected and incomplete code snipped...]

V

Here's it all in one source as the poster requested.

#include <iostream>

class obj;

typedef templateptr<obj> obj_ptr;

class starter
{
public:
starter() {}
~starter() {}

obj_ptr p;

};

template <class T>

class templateptr
: public defclass::base
{
public:
inline templateptr(T* p = 0);

};

template <class T>
inline
templateptr<T>::templateptr(T* p)
: defclass::base(p)
{

}

class defclass
{
public:

class base
{
public:
// base (base b);
base (defclass* p = 0);

defclass *m_ref;

};

friend class base;

};

defclass::base(defclass *p)
: m_ref(p)
{

}

class obj
: public defclass
{
public:
obj() {}
~obj() {}
};


int main(void)
{
starter s;

return 0;

}
 
R

red floyd

Keith said:
#include <iostream> unneeded.

class obj;

typedef templateptr<obj> obj_ptr;

templateptr undefined here
class starter
{
public:
starter() {}
~starter() {}

obj_ptr p;
because obj_ptr is not defined (see above), this is an error.
};

template <class T>

class templateptr
: public defclass::base

defclass::base undefined here
{
public:
inline templateptr(T* p = 0);

};

template <class T>
inline
templateptr<T>::templateptr(T* p)
: defclass::base(p)
{

}

class defclass
{
public:

class base
{
public:
// base (base b);
base (defclass* p = 0);

defclass *m_ref;

};

friend class base;

};

defclass::base(defclass *p)

should be defclass::base::base
 
V

Victor Bazarov

Keith said:
Keith said:
I'm switching from the HP-UX compiler aCC 5.55 to aCC 6.13 and I get
the following error:
"templateptr.h", line 20: error #2289: no instance
of constructor "defclass::base::base" matches the
argument list
argument types are: (obj *)
: defclass::base(p)
^
detected during instantiation of
"templateptr<T>::templateptr(T *) [with
T=obj]" at line 50 of
"starter.h"
Since an obj is derived from a defclass, I don't see the problem.
The line I'm using to compile is:
/opt/bin/aCC -o main main.cxx
I'm also getting similar issues on a linux box with GCC 3.4.6 and it
wasn't an issue with 3.2.3.
I was thinking it might be the new two name lookup in the new
compiler but passing +dep_name and +nodep_name switches are making
no difference.
Does anyone have any ideas on it?

Please collect all the code in _one_ module, and post it *again*.
[...disconnected and incomplete code snipped...]

V

Here's it all in one source as the poster requested.

You just dumped it in one file and didn't even bother to see if it
compiles, didn't you? Well, if you don't want our help, that's fine.

BTW, after rearranging properly your code doesn't compile because
you forgot "::base" in one place. After adding that it should
compile fine. If it still doesn't compile with whatever compiler
you got, contact their tech support.

V
 
K

Keith Halligan

You just dumped it in one file and didn't even bother to see if it
compiles, didn't you? Well, if you don't want our help, that's fine.

BTW, after rearranging properly your code doesn't compile because
you forgot "::base" in one place. After adding that it should
compile fine. If it still doesn't compile with whatever compiler
you got, contact their tech support.

V

I apologise in advance about the code not being compiled. I was in a
bit of a rush yesterday.

The code as it is now will compile in aCC 6.1.3.

If anyone has any ideas about the code, then I'd appreciate it.


#include <iostream>


// Defclass.h
//

class obj;

class defclass
{
public:

class base
{
public:
// base (base b);
base (defclass* p = 0);

defclass *m_ref;

};

friend class base;

};


defclass::base::base(defclass *p)
: m_ref(p)
{
}

//
// templateptr.h

template <class T>
class templateptr
: public defclass::base
{
public:
inline templateptr(T* p = 0);

};


template <class T>
inline
templateptr<T>::templateptr(T* p)
: defclass::base(p)
{

}

typedef templateptr<obj> obj_ptr;


//
// starter.h

class starter
{
public:
starter() {}
~starter() {}

obj_ptr p;

};



class obj
: public defclass
{
public:
obj() {}
~obj() {}

};

//
// main.cxx

int main(void)
{
starter s;

return 0;
}
 
J

Jim Langston

Keith Halligan said:
You just dumped it in one file and didn't even bother to see if it
compiles, didn't you? Well, if you don't want our help, that's fine.

BTW, after rearranging properly your code doesn't compile because
you forgot "::base" in one place. After adding that it should
compile fine. If it still doesn't compile with whatever compiler
you got, contact their tech support.

V

I apologise in advance about the code not being compiled. I was in a
bit of a rush yesterday.

The code as it is now will compile in aCC 6.1.3.

If anyone has any ideas about the code, then I'd appreciate it.


#include <iostream>


// Defclass.h
//

class obj;

class defclass
{
public:

class base
{
public:
// base (base b);
base (defclass* p = 0);

defclass *m_ref;

};

friend class base;

};


defclass::base::base(defclass *p)
: m_ref(p)
{
}

//
// templateptr.h

template <class T>
class templateptr
: public defclass::base
{
public:
inline templateptr(T* p = 0);

};


template <class T>
inline
templateptr<T>::templateptr(T* p)
: defclass::base(p)
{

}

typedef templateptr<obj> obj_ptr;


//
// starter.h

class starter
{
public:
starter() {}
~starter() {}

obj_ptr p;

};



class obj
: public defclass
{
public:
obj() {}
~obj() {}

};

//
// main.cxx

int main(void)
{
starter s;

return 0;
}

This compiles and runs without error in Microsoft Visual C++ .net 2003
 
K

Keith Halligan

You just dumped it in one file and didn't even bother to see if it
compiles, didn't you? Well, if you don't want our help, that's fine.
[..]
BTW, after rearranging properly your code doesn't compile because
you forgot "::base" in one place. After adding that it should
compile fine. If it still doesn't compile with whatever compiler
you got, contact their tech support.
V
I apologise in advance about the code not being compiled. I was in a
bit of a rush yesterday.
The code as it is now will compile in aCC 6.1.3.
If anyone has any ideas about the code, then I'd appreciate it.
#include <iostream>
// Defclass.h
//
class obj;
class defclass
{
public:
class base
{
public:
// base (base b);
base (defclass* p = 0);
defclass *m_ref;

friend class base;

defclass::base::base(defclass *p)
: m_ref(p)
{
}
//
// templateptr.h
template <class T>
class templateptr
: public defclass::base
{
public:
inline templateptr(T* p = 0);

template <class T>
inline
templateptr<T>::templateptr(T* p)
: defclass::base(p)
{

typedef templateptr<obj> obj_ptr;
//
// starter.h
class starter
{
public:
starter() {}
~starter() {}
obj_ptr p;

class obj
: public defclass
{
public:
obj() {}
~obj() {}

//
// main.cxx
int main(void)
{
starter s;
return 0;
}

This compiles and runs without error in Microsoft Visual C++ .net 2003

Yes Jim I don't doubt that it does, but on the HP-UX compiler aCC
6.1.3 and the GNU compiler (linux) gcc 3.4.6 it won't.

It's almost certainly down to something regarding making template code
more strict and conformant to the C++ standard.

Regards
Keith
 
V

Victor Bazarov

Keith said:
[.. code ..]
This compiles and runs without error in Microsoft Visual C++ .net
2003

Yes Jim I don't doubt that it does, but on the HP-UX compiler aCC
6.1.3 and the GNU compiler (linux) gcc 3.4.6 it won't.

It still does with VC++ 2005, and won't with Comeau C++ online trial.

"ComeauTest.c", line 49: error: no instance of constructor
"defclass::base::base"
matches the argument list
The argument types that you used are: (obj *)
: defclass::base(p)
^
detected during instantiation of
It's almost certainly down to something regarding making template code
more strict and conformant to the C++ standard.

It doesn't compile because the relationship between 'obj' and 'defclass'
is not known to the compiler at the time when 'templateptr' gets first
instantiated. If you move the definition of 'obj' before 'starter', it
compiles. Different compilers do it differently, I guess.

Curiously, if I pull 'base' out of 'defclass', it compiles in its original
form.

V
 
V

Victor Bazarov

Victor said:
[..]
It doesn't compile because the relationship between 'obj' and
'defclass' is not known to the compiler at the time when
'templateptr' gets first instantiated. If you move the definition of
'obj' before 'starter', it compiles. Different compilers do it
differently, I guess.

Also, try putting the implementation of the 'templateptr' c-tor
after the 'obj' class definition. Comeau likes that as well.
Curiously, if I pull 'base' out of 'defclass', it compiles in its
original form.

V
 
K

Keith Halligan

Victor said:
[..]
It doesn't compile because the relationship between 'obj' and
'defclass' is not known to the compiler at the time when
'templateptr' gets first instantiated. If you move the definition of
'obj' before 'starter', it compiles. Different compilers do it
differently, I guess.

Also, try putting the implementation of the 'templateptr' c-tor
after the 'obj' class definition. Comeau likes that as well.
Curiously, if I pull 'base' out of 'defclass', it compiles in its
original form.

V

Hi Victor,

Thanks for your feedback, you are right in the suggestions you gave,
they do work, on both compilers.

I was under the illusion that it was something to do with name lookup
(especially in the case of gcc3.4) as they began a two-phase name
lookup for template code, and a lot of the templated changes broke a
lot of older code.
 

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,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top