473,466 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

templated code not able to call correct constructor

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<objobj_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() {}

};

May 1 '07 #1
10 2205
Keith Halligan wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 1 '07 #2
On May 1, 6:08 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Keith Halligan wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Here's it all in one source as the poster requested.

#include <iostream>

class obj;

typedef templateptr<objobj_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;

}
May 1 '07 #3
Keith Halligan wrote:
>

#include <iostream>
unneeded.
>
class obj;

typedef templateptr<objobj_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
: m_ref(p)
{

}

class obj
: public defclass
{
public:
obj() {}
~obj() {}
};
int main(void)
{
starter s;

return 0;

}
May 1 '07 #4
Keith Halligan wrote:
On May 1, 6:08 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>Keith Halligan wrote:
>>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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 1 '07 #5
On May 1, 7:37 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
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<objobj_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;
}
May 2 '07 #6
"Keith Halligan" <ke************@gmail.comwrote in message
news:11********************@e65g2000hsc.googlegrou ps.com...
On May 1, 7:37 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>>
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

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<objobj_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
May 2 '07 #7
On May 2, 10:19 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
"Keith Halligan" <keith.halli...@gmail.comwrote in message

news:11********************@e65g2000hsc.googlegrou ps.com...
On May 1, 7:37 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
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<objobj_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

May 2 '07 #8
Keith Halligan wrote:
On May 2, 10:19 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
>[.. 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
"templateptr<T>::templateptr(T *) [with T=obj]" at line
63
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 2 '07 #9
Victor Bazarov wrote:
[..]
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 2 '07 #10
On May 2, 3:59 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Victor Bazarov wrote:
[..]
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
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.


May 2 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: tirath | last post by:
Hi all, I have a templated class that derives from a non-templated abstract class. How do I then cast a base class pointer to a <templated> derived class pointer in a generalised fashion? ...
2
by: ferdinand.stefanus | last post by:
Hi, I have some questions regarding templated class constructor: #include <iostream> using namespace std; template<typename T> class Foo { public:
9
by: Jon Wilson | last post by:
I have a class which needs to accumulate data. The way we get this data is by calling a member function which returns float on a number of different objects of different type (they are all the...
5
by: kalita | last post by:
template<class T> class A { template<class Y> A(const A<Y> &) { // whatever } };
6
by: Dan Huantes | last post by:
I was presented a problem today where a class had member variable that was an object of a templated class. The class wanted to instantiate the object as a private member variable and call a...
7
by: Claudius | last post by:
Hello, in my class TopTen I need to define three constructors while only the last one, the most general in terms of templates, should be sufficient in my opinion: template <typename Tnum,...
3
by: Lawrence Spector | last post by:
How does one call a templated constructor inside of a class when instantiating an object? I made up a quick sample to demonstrate. #include <iostream> class TestClass { public: template...
2
by: domehead100 | last post by:
I have a templated class, CDerived: template <typename TValue, typename TDraw, typename TEdit ...> class CDerived : public CBase { TValue m_Value public: TValue& GetValue() const {
2
card
by: card | last post by:
Hi everyone, I have a question about referencing a nested class contained within a templated class. Of course the best way to show you is by example. Here's my templated classes: #include...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.