473,763 Members | 7,727 Online
Bytes | Software Development & Data Engineering Community
+ 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 "templatept r.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::b ase(defclass *p)
: m_ref(p)
{
}
----------
obj.h
---------
#include "defclass.h "
class obj
: public defclass
{
public:
obj() {}
~obj() {}

};

May 1 '07 #1
10 2225
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...@com Acast.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<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;

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

#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
: 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...@com Acast.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...@com Acast.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<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;
}
May 2 '07 #6
"Keith Halligan" <ke************ @gmail.comwrote in message
news:11******** ************@e6 5g2000hsc.googl egroups.com...
On May 1, 7:37 pm, "Victor Bazarov" <v.Abaza...@com Acast.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<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
May 2 '07 #7
On May 2, 10:19 am, "Jim Langston" <tazmas...@rock etmail.comwrote :
"Keith Halligan" <keith.halli... @gmail.comwrote in message

news:11******** ************@e6 5g2000hsc.googl egroups.com...
On May 1, 7:37 pm, "Victor Bazarov" <v.Abaza...@com Acast.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<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

May 2 '07 #8
Keith Halligan wrote:
On May 2, 10:19 am, "Jim Langston" <tazmas...@rock etmail.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

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

Similar topics

3
6576
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? Here's what I'm generally trying to achieve: I'm building (trying to anyway) a serialization library. Here's my design:
2
1918
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
2318
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 same type for a given instance of the class, but different types for different instances.) #include<set> using namespace std; template<class T>
5
4243
by: kalita | last post by:
template<class T> class A { template<class Y> A(const A<Y> &) { // whatever } };
6
1526
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 constructor other than the default constructor. I couldn't figure out why it wasn't working so I changed the member variable to a pointer to an object instead and intialized it in the constructor and destroyed in the destructor. It bothered me that...
7
1729
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, short Trank, bool Tcont> TopTen<Tnum,Trank,Tcont>::TopTen( const TopTen<Tnum,Trank,Tcont& tten );
3
12162
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 <class T> TestClass()
2
2935
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
2289
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 <stack> template <class T> class A { public:
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10144
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9997
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9937
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7366
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3917
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 we have to send another system
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.