By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,677 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,677 IT Pros & Developers. It's quick & easy.

Compilation errors in templated code

P: n/a
template<template<typename T> class StoragePolicy>
class construction_info {
// Empty by default, specialize for other types.
};

template<template<typename> class StoragePolicy,
typename ConversionPolicy = DefaultConversions>
class Settings
{
public:

// Construct from construction_info.
Settings(const construction_info<StoragePolicy> &info)
: policy_(info)
{
policy_.Read();
}

private:

// A copy of a constructed data policy.
StoragePolicy<ConversionPolicy> policy_;
};

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template<typename ConversionPolicy>
class Xml
{
public:

// Typedef for quicker typing.
typedef construction_info<Xml> ctor_info; // ERROR!?

// Construct from ctor_info (definition after the class).
Xml(const ctor_info &info)
: c_info_(info) { }

void Read() {
std::cout << "XMLREAD" << std::endl;
}

private:
ctor_info c_info_; // Construction info
};

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template<>
class construction_info<Xml>
{
public:
construction_info(const std::string &filepath)
: filepath_(filepath) {}

std::string filepath_;
};

typedef construction_info<Xml> make_xml;

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Settings<Xml> xml( make_xml("D:\\file.xml") );

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// DJGPP compiles everything, but msvc.net2k3
// issues this:
//
// d:\code\tests\sett\xml.hpp(19): error C3200:
// 'Xml<ConversionPolicy>' : invalid template argument
// for template parameter 'StoragePolicy', expected a class template
//
// d:\code\tests\sett\xml.hpp(19): error C3200:
// 'Xml<ConversionPolicy>' : invalid template argument
// for template parameter 'StoragePolicy', expected a class template
// with
// [
// ConversionPolicy=DefaultConversions
// ]
//

Any suggestions?
Jul 22 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Saulius wrote:
template<template<typename T> class StoragePolicy>
What's that supposed to mean?
class construction_info {
// Empty by default, specialize for other types.
};
....
Any suggestions?


ITYM:

template< typename StoragePolicy >
class construction_info {
// Empty by default, specialize for other types.
};

Jul 22 '05 #2

P: n/a
Jeff Schwab wrote:
Saulius wrote:
template<template<typename T> class StoragePolicy>

What's that supposed to mean?
class construction_info {
// Empty by default, specialize for other types.
};

...
Any suggestions?

ITYM:

template< typename StoragePolicy >
class construction_info {
// Empty by default, specialize for other types.
};


Augh! Ignore that, please. :(

Your code compiles just fine with GCC 3.3.

Jul 22 '05 #3

P: n/a
Saulius wrote in news:a3**************************@posting.google.c om:
template<typename ConversionPolicy>
class Xml
{
public:

// Typedef for quicker typing.
typedef construction_info<Xml> ctor_info; // ERROR!?
typedef construction_info< ::Xml > ctor_info;

Within the declaration of this class template Xml is the type
Xml< ConversionPolicy > *not* the template, the explicit
namespace qualification fixes that.


// Construct from ctor_info (definition after the class).


Note that the space in "< ::Xml" is important, without it you
get a di/trigraph and therfore some wierd compilation error.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #4

P: n/a
Rob Williscroft <rt*@freenet.REMOVE.co.uk> wrote in message news:<Xn********************************@195.129.1 10.131>...
Saulius wrote in news:a3**************************@posting.google.c om:
template<typename ConversionPolicy>
class Xml
{
public:

// Typedef for quicker typing.
typedef construction_info<Xml> ctor_info; // ERROR!?


typedef construction_info< ::Xml > ctor_info;

Within the declaration of this class template Xml is the type
Xml< ConversionPolicy > *not* the template, the explicit
namespace qualification fixes that.


// Construct from ctor_info (definition after the class).


Note that the space in "< ::Xml" is important, without it you
get a di/trigraph and therfore some wierd compilation error.

Rob.


Now it won`t let me specialize construction_info for Xml:

d:\code\tests\sett\xml.hpp(44): error C2908: explicit specialization;
'settings::construction_info<StoragePolicy>' has already been
instantiated
with
[
StoragePolicy=settings::Xml
]
d:\code\tests\sett\xml.hpp(50): error C2766: explicit specialization;
'settings::construction_info<settings::Xml>' has already been defined

(settings is the namespace in witch everything`s written)
Jul 22 '05 #5

P: n/a
Saulius wrote in news:a3**************************@posting.google.c om:
Now it won`t let me specialize construction_info for Xml:

d:\code\tests\sett\xml.hpp(44): error C2908: explicit specialization;
'settings::construction_info<StoragePolicy>' has already been
instantiated
with
[
StoragePolicy=settings::Xml
]
d:\code\tests\sett\xml.hpp(50): error C2766: explicit specialization;
'settings::construction_info<settings::Xml>' has already been defined

(settings is the namespace in witch everything`s written)


Ok I actually spotted this the first time, but there were
other errors (DefaultConversions, std::cout, std::endl),
that I assumed, wrongly, had something to do with it.

CBuilder preview (an EDG front end) gives the error a bit
more legably than VC7.1 : explicit specialization of class
.... must precede its first use.

I had to put:

#include <iostream>
#include <ostream>
#include <string>

class DefaultConversions {};

/* from original code ...
*/
template<template<typename T> class StoragePolicy>
class construction_info {
// Empty by default, specialize for other types.
};

/* forward declare the Xml template
*/
template <typename ConversionPolicy> class Xml;

/* Moved forward ...
*/
template<>
class construction_info< Xml >
{
public:
construction_info(const std::string &filepath)
: filepath_(filepath) {}

std::string filepath_;
};

As the begining of your posted code to fix this, remove the
specialization from the end ofcourse :).
Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #6

P: n/a

"Saulius" <sa****@balticum-tv.lt> wrote in message
news:a3**************************@posting.google.c om...
template<template<typename T> class StoragePolicy>
class construction_info {
// Empty by default, specialize for other types.
};

template<template<typename> class StoragePolicy,
typename ConversionPolicy = DefaultConversions>
class Settings
{
public:

// Construct from construction_info.
Settings(const construction_info<StoragePolicy> &info)
: policy_(info)
{
policy_.Read();
}

private:

// A copy of a constructed data policy.
StoragePolicy<ConversionPolicy> policy_;
};

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template<typename ConversionPolicy>
class Xml
{
public:

// Typedef for quicker typing.
typedef construction_info<Xml> ctor_info; // ERROR!?


Note you are defining a templated class so the template parameters are
deduced when you instantiate the class.
simply remove the template parameters i.e:
typedef construction_info ctor_info;

This should compile fine then if you include the <string> header for
std::string.

HTH.
Jul 22 '05 #7

P: n/a

"Jumbo @uko2.co.uk>" <pcr1000011<nospam> wrote in message
news:10***************@news.minx.net.uk...

"Saulius" <sa****@balticum-tv.lt> wrote in message
news:a3**************************@posting.google.c om...
template<template<typename T> class StoragePolicy>
class construction_info {
// Empty by default, specialize for other types.
};

template<template<typename> class StoragePolicy,
typename ConversionPolicy = DefaultConversions>
class Settings
{
public:

// Construct from construction_info.
Settings(const construction_info<StoragePolicy> &info)
: policy_(info)
{
policy_.Read();
}

private:

// A copy of a constructed data policy.
StoragePolicy<ConversionPolicy> policy_;
};

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template<typename ConversionPolicy>
class Xml
{
public:

// Typedef for quicker typing.
typedef construction_info<Xml> ctor_info; // ERROR!?
Note you are

oops typedeffing I mean
a templated class so the template parameters are deduced when you instantiate the class.
simply remove the template parameters i.e:
typedef construction_info ctor_info;

This should compile fine then if you include the <string> header for
std::string.

HTH.

How did this end up here? :-s


Jul 22 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.