473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Namespace/Template member initialization issue

Hi,

I am having a problem writing a constructor/member initialization with
VC.NET7.1.

Here is the code:

---

namespace Library
{
template <typename T>
class LibraryTemplateT
{ };
}

namespace Module
{
class ModuleObject : public Library::LibraryTemplateT<int>
{
public:
ModuleObject() throw();
};

// [1] FAILS: error C2614: 'Module::ModuleObject' : illegal member
initialization: 'LibraryTemplateT' is not a base or member
// ModuleObject::ModuleObject() throw() : LibraryTemplateT()
// { }

// [2] FAILS: error C2059: syntax error : '<'
// ModuleObject::ModuleObject() throw() : LibraryTemplateT<int>()
// { }

// [3] WORKS
ModuleObject::ModuleObject() throw() : Library::LibraryTemplateT<int>()
{ }

}
---

The weird thing is that if LibraryTemplateT is a class and not a template
then I am able to use the first option above and not have to manually
specify the Library namespace. Also, all three choices work when trying them
online at http://www.comeaucomputing.com/tryitout/.

Since I have existing code that is using option [1] above for non-templates
I would like to know:

- Is the code illegal (for both templates and regular classes). ie. is
option [3] the only legal way to write that code (without having a using
declaration)?
- Are templates somehow special and get resolved differently?
- Is this a bug?

Thanks
Jul 19 '05 #1
3 5906

"Brian Ross" <br**********@rogers.com> wrote in message
news:ZH********************@news04.bloor.is.net.ca ble.rogers.com...
Hi,

I am having a problem writing a constructor/member initialization with
VC.NET7.1.

Here is the code:

---

namespace Library
{
template <typename T>
class LibraryTemplateT
{ };
}

namespace Module
{
class ModuleObject : public Library::LibraryTemplateT<int>
{
public:
ModuleObject() throw();
};

// [1] FAILS: error C2614: 'Module::ModuleObject' : illegal member
initialization: 'LibraryTemplateT' is not a base or member
// ModuleObject::ModuleObject() throw() : LibraryTemplateT()
// { }

// [2] FAILS: error C2059: syntax error : '<'
// ModuleObject::ModuleObject() throw() : LibraryTemplateT<int>()
// { }

// [3] WORKS
ModuleObject::ModuleObject() throw() : Library::LibraryTemplateT<int>() { }

}
---

The weird thing is that if LibraryTemplateT is a class and not a template
then I am able to use the first option above and not have to manually
specify the Library namespace. Also, all three choices work when trying them online at http://www.comeaucomputing.com/tryitout/.

Since I have existing code that is using option [1] above for non-templates I would like to know:

- Is the code illegal (for both templates and regular classes). ie. is
option [3] the only legal way to write that code (without having a using
declaration)?
- Are templates somehow special and get resolved differently?
- Is this a bug?

Thanks


The following code compiles for me using VC++ 7.1

namespace Library
{
template <typename T>
class LibraryTemplateT
{ };
}
namespace Module
{
class ModuleObject : public Library::LibraryTemplateT<int>
{
public:
ModuleObject() throw() {}
};
}
int main()
{
Module::ModuleObject m;
}

Suggest you post the exact code you are having trouble with.

john
Jul 19 '05 #2

"John Harrison" <jo*************@hotmail.com> wrote in message
news:bh************@ID-196037.news.uni-berlin.de...

"Brian Ross" <br**********@rogers.com> wrote in message
news:ZH********************@news04.bloor.is.net.ca ble.rogers.com...
Hi,

I am having a problem writing a constructor/member initialization with
VC.NET7.1.

Here is the code:

---

namespace Library
{
template <typename T>
class LibraryTemplateT
{ };
}

namespace Module
{
class ModuleObject : public Library::LibraryTemplateT<int>
{
public:
ModuleObject() throw();
};

// [1] FAILS: error C2614: 'Module::ModuleObject' : illegal member
initialization: 'LibraryTemplateT' is not a base or member
// ModuleObject::ModuleObject() throw() : LibraryTemplateT()
// { }

// [2] FAILS: error C2059: syntax error : '<'
// ModuleObject::ModuleObject() throw() : LibraryTemplateT<int>()
// { }

// [3] WORKS
ModuleObject::ModuleObject() throw() :

Library::LibraryTemplateT<int>()
{ }

}
---

The weird thing is that if LibraryTemplateT is a class and not a template then I am able to use the first option above and not have to manually
specify the Library namespace. Also, all three choices work when trying

them
online at http://www.comeaucomputing.com/tryitout/.

Since I have existing code that is using option [1] above for

non-templates
I would like to know:

- Is the code illegal (for both templates and regular classes). ie. is
option [3] the only legal way to write that code (without having a using
declaration)?
- Are templates somehow special and get resolved differently?
- Is this a bug?

Thanks


The following code compiles for me using VC++ 7.1

namespace Library
{
template <typename T>
class LibraryTemplateT
{ };
}
namespace Module
{
class ModuleObject : public Library::LibraryTemplateT<int>
{
public:
ModuleObject() throw() {}
};
}
int main()
{
Module::ModuleObject m;
}

Suggest you post the exact code you are having trouble with.


Hi,

I think you missed the part where I mentioned that I have tried your
combination and I know that it works (look at the comments in my sample
code). My question was more about why the other variations work when not
using templates and if that code is illegal.

Brian
Jul 19 '05 #3
>
Hi,

I think you missed the part where I mentioned that I have tried your
combination and I know that it works (look at the comments in my sample
code). My question was more about why the other variations work when not
using templates and if that code is illegal.

Brian


You're right I missed the point, sorry about that. I surprised that 1 and 2
work at all even for non-templates, so I don't think I should say any more.

john
Jul 19 '05 #4

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

Similar topics

7
by: Drew McCormack | last post by:
I have a C++ template class which contains a static variable whose construction registers the class with a map. Something like this: template <typename T> class M { static Registrar<M>...
8
by: Exits Funnel | last post by:
Hello, I've been tasked with porting some C++ code from Windows to Linux. The following excerpt is giving me trouble: //BEGIN CODE #include <string> class TempTestBase_t {
5
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ...
7
by: ank | last post by:
Hi, I was curious about how to define static data member of template class. Should I put the definition in a separate source file or in the same header file as its template class? And when this...
8
by: Ferdi Smit | last post by:
I've never understood the rationale of allowing partial, but not explicit specialization for classes at non-namespace scope. Ie.: struct A { template <typename T1, typename T2> struct B {}; ...
20
by: Patrick Guio | last post by:
Dear all, I have some problem with insertion operator together with namespace. I have a header file foo.h containing declaration of classes, typedefs and insertion operators for the typedefs in...
2
by: Brian Ross | last post by:
Hi, I am having a problem writing a constructor/member initialization with VC.NET7.1. Here is the code: --- namespace Library
11
by: Niels Dekker - no reply address | last post by:
The following attempt to pass my template "Base" as a template template argument was rejected by Microsoft VC++ 8.0 (2005), while it still works on VC++ 7.1 (2003). Is it correct C++? And is...
5
by: chgans | last post by:
Hi all, I'm having difficulties with some template static member, especially when this member is a template instance, for example: ---- template<typename T> class BaseT { public: static...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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...

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.