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

Crazy Local Class

P: n/a
Hi,
I have a local class inside a function template. I am able to wrap
any type in my local class. Is it legal C++? What type of class is
Local? Is it a class template or regular class?
Thanks in advance.
--dhina
---------------------------------------------------------------------------------------------------------------------------------------------
class Foo
{
public:
virtual ~Foo() {}
virtual void print() = 0;
};

template< typename T >
Foo* wrap(const T& t)
{
class Local : public Foo
{
public:
Local(const T& t):val_(t) { }
void print()
{
cout << "In Local::print()" << val_ << endl;
}
private:
T val_;
};
return new Local(t);
}

int main(void)
{
int x = 50;
Foo* ptr = wrap(x);
ptr->print();
std::string s("wrap");
ptr = wrap(s);
ptr->print();
}

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Oct 23 '08 #1
Share this Question
Share on Google+
28 Replies


P: n/a
Local is a non-template class. A local class can improve locality of
symbols. The type of the class can be used as a template argument and
so it is not entirely hidden because its local to a function.

Fraser.
Oct 23 '08 #2

P: n/a
On Oct 23, 3:36*pm, "Fraser Ross" <z...@zzzzzz.comwrote:
Local is a non-template class. *A local class can improve
locality of symbols. *The type of the class can be used as a
template argument and so it is not entirely hidden because its
local to a function.
Not sure I understand what you are trying to say, but a local
class cannot be used as a template argument.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Oct 23 '08 #3

P: n/a
"James Kanze"
>Not sure I understand what you are trying to say, but a local
class cannot be used as a template argument.
Its in the draft at 14.3.1/2.

Fraser.
Oct 24 '08 #4

P: n/a
SG
On 24 Okt., 09:45, "Fraser Ross" <z...@zzzzzz.comwrote:
>[...] but a local class cannot be used as a template argument.
Its in the draft at 14.3.1/2.
For C++0x, yes. But it doesn't work now.

Cheers,
SG
Oct 24 '08 #5

P: n/a
On Oct 23, 4:58 am, cplusle...@gmail.com wrote:
I have a local class inside a function template. I am able to wrap
any type in my local class.
It is a common C++ idiom sometimes called type erasure.
Is it legal C++?
It is legal.
What type of class is Local?
The one declared in a function scope.
Is it a class template or regular class?
Class template is not a class in a general sense, until you
instantiate it. Once a class template is instantiated it yields a
class. Thus, local class is a class.

--
Max

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Oct 24 '08 #6

P: n/a
On Oct 23, 5:58 am, cplusle...@gmail.com wrote:
Hi,
I have a local class inside a function template. I am able to wrap
any type in my local class. Is it legal C++? What type of class is
Local? Is it a class template or regular class?
Like members of a class template, be they data members, functions, or
inner types, local classes in template functions are template
"members", meaning that there is one version per instantiation of the
outer template.

Sebastian
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Oct 24 '08 #7

P: n/a
HL
On Oct 23, 11:58 am, cplusle...@gmail.com wrote:
Hi,
I have a local class inside a function template. I am able to wrap
any type in my local class. Is it legal C++? What type of class is
Local? Is it a class template or regular class?
Thanks in advance.
--dhina
This is absolutedly legal C++. As an answer, local class refer to all
classes are not defined in global, namespace scopes. In your codes,
Foo is regular class. However, I am not sure if Local is a template.
Just like we don't usually call a member in a template class template
method, I don't call a class in a template method template class. Even
when deducting, there will be 2 Locals; Local with int and Local with
string, but they are different types and both in local scope. Maybe I
can use this term: wrap<int>::Local and wrap<std::string>::Local.
But if it's a template really doesn't matter, does it?
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Oct 24 '08 #8

P: n/a
Gil
On Oct 22, 11:58 pm, cplusle...@gmail.com wrote:
Hi,
I have a local class inside a function template. I am able to wrap
any type in my local class.
you're not able to wrap _any_ type just types that model:
CopyConstructibleConcept and (based on your example),
OutputStreamableConcept.

you can find some good info on discriminated types
(holders that can contain different types) here:
http://www.two-sdg.demon.co.uk/curbr...onversions.pdf
Is it legal C++?
the exercised idiom (the local class itself) is perfectly legal
and imo interesting C++ code.
what makes it different than a placeholder approach like boost::any
is the simple memory management left entirely to user as opposed to
RAII exercised by boost::any.
judging by your example some form of RAII would have been better:)

the example has small(?) imperfections though:
missing delete ptr and missing return in main,
non-const pure virtual print in Foo etc.
What type of class is
Local? Is it a class template or regular class?
it's a 'regular' local class with no linkage but visible to RTTI
mechanism.
it models also an Adaptor to an already deduced type (that's the
interesting part).
it makes use of some sort of external polymorphism idiom by deriving
from a common interface for non related types.

beside boost::any you can also check boost::variant and Qt's QVariant
if you want to see some different implementations of discriminated
types.

cheers,
gill
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Oct 24 '08 #9

P: n/a
On Oct 23, 5:58 am, cplusle...@gmail.com wrote:
I have a local class inside a function template. I am able to
wrap any type in my local class. Is it legal C++?
Sure.
What type of class is Local? Is it a class template or
regular class?
You can't define a template in local scope, period. You can
define a class, with two restrictions: all member functions must
be defined within the class definition, and the class may have
no static data members. Other than that, it's exactly like any
other class (except, obviously, for the name binding of the
class name.
class Foo
{
public:
virtual ~Foo() {}
virtual void print() = 0;
};
template< typename T >
Foo* wrap(const T& t)
{
class Local : public Foo
Here, Local is NOT a template. But you have a distinct Local
(defined differently) for each instantiation of wrap, which
makes it act like a template in some ways.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Oct 24 '08 #10

P: n/a
cp********@gmail.com writes:
I have a local class inside a function template. I am able to wrap
any type in my local class. Is it legal C++? What type of class is
Local? Is it a class template or regular class?
Yes, this is legal C++. Local is a normal class, but there is a
separate type for each instantiation of wrap<>.
template< typename T >
Foo* wrap(const T& t)
{
class Local : public Foo
{
public:
Local(const T& t):val_(t) { }
void print()
{
cout << "In Local::print()" << val_ << endl;
}
private:
T val_;
};
return new Local(t);
}
Anthony
--
Anthony Williams | Just Software Solutions Ltd
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Oct 24 '08 #11

P: n/a
On Oct 24, 9:45*am, "Fraser Ross" <z...@zzzzzz.comwrote:
"James Kanze"
Not sure I understand what you are trying to say, but a local
class cannot be used as a template argument.
Its in the draft at 14.3.1/2.
I had heard that there had been a proposal to allow it, but I
was too lazy to look-up whether it had been adopted. But it's
still illegal in current C++ (C++03).

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Oct 25 '08 #12

P: n/a
Any non external entity can't be a template argument at present.

I want to use a string literal as an argument for a non-type parameter
but that can't be done. Is that a sensible restriction?

Fraser.
Oct 25 '08 #13

P: n/a
In the standards example below neither constructor is accessible and
only one is used.

template<class T, char* pclass X {
X();
X(const char* q) { }
};
X<int, "Studebaker"x1; // error: string literal as template-argument
char p[] = "Vivisectionist";
X<int,px2; // OK

Fraser.
Oct 25 '08 #14

P: n/a
On 2008-10-25 12:08:41 -0400, "Fraser Ross" <z@zzzzzz.comsaid:
>
I want to use a string literal as an argument for a non-type parameter
but that can't be done. Is that a sensible restriction?
Yes. Two string literals with the same sequence of characters can be at
the same address or at different addresses. So:

template <const char *class C
{
};

C<"asdf"c0;
C<"asdf"c1 = c0;

c0 and c1 could be the same type or they could be different types, so
in some cases the initialization of c1 would fail, and in others it
would succeed.

The way to do this is:

const char *param = "asdf";

C<paramc0;
C<paramc1 = c0; // OK

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Oct 25 '08 #15

P: n/a
"Pete Becker"
const char *param = "asdf";

C<paramc0;
C<paramc1 = c0; // OK
param can't be at block scope which loses the locality of symbols. If a
function is small they won't be that far away.

Fraser.
Oct 25 '08 #16

P: n/a
"Pete Becker"
Yes. Two string literals with the same sequence of characters can be
at
the same address or at different addresses. So:

template <const char *class C
{
};

C<"asdf"c0;
C<"asdf"c1 = c0;

c0 and c1 could be the same type or they could be different types, so
in some cases the initialization of c1 would fail, and in others it
would succeed.
That could be the programmers responsibility.

Fraser.
Oct 25 '08 #17

P: n/a
>
the example has small(?) imperfections though:
missing delete ptr and missing return in main,
non-const pure virtual print in Foo etc.
Thank you all for the comments. I hope boost::shared_ptr will solve
the resource issue

template< typename T >
boost::shared_ptr<Foowrap(const T& t)
{
class Local : public Foo
{
......
};
return boost::shared_ptr<Foo>(new Local(t));
}

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Oct 25 '08 #18

P: n/a
cp********@gmail.com wrote:
I have a local class inside a function template. I am able to wrap
any type in my local class. Is it legal C++?
Yes, and you actually seem to have made decent use of a potentially
confusing language feature. Nicely done.
What type of class is Local?
Local isn't really a class yet. Each non-specialized instantiation of
the "wrap" function template will be a function, and will include, as
part of its definition, a local class called Local. Each such local
class will be distinct from the others. The name Local will be
meaningful only within the context of its enclosing scope, i.e. within
the definition of the function that is an instantiation of the "wrap"
function template. See also section 9.8 of the current standard,
[class.local].
Is it a class template or regular class?
It's part of the primary definition of a function template; IOW, it's a
blueprint for a class definition, but is neither a template nor a class
in its own right.

Local specifically cannot a template, because templates names have
linkage, whereas Local specifically does not. Local isn't even allowed
to have any member templates.

On the other hand, Local is not a class, but part of a code generation
mechanism that is capable of producing classes as needed. Especially
noteworthy is the fact that different instantiations of the function
template will generate entirely distinct classes based on Local; for
example:

struct foo { virtual ~foo() { } };

template<typename T>
foo* distinct(foo* f =0) {
struct Bar: foo { };
return dynamic_cast<Bar*>(f) ? 0 : new Bar;
}

struct t1;
struct t2;

#include <iostream>

int main() {
foo* const f = distinct<t1>();
std::cout << !!distinct<t1>(f) << '\n'; // 0
std::cout << !!distinct<t2>(f) << '\n'; // 1
}

class Foo
{
public:
virtual ~Foo() {}
virtual void print() = 0;
};
Foo is a class.
template< typename T >
Foo* wrap(const T& t)
{
As you said, wrap is a function template.
class Local : public Foo
{
public:
Local(const T& t):val_(t) { }
void print()
{
cout << "In Local::print()" << val_ << endl;
}
private:
T val_;
};
return new Local(t);
}
Nicely done, except that ownership of the dynamically allocated object
is not clear. You might consider returning a more sophisticated pointer
type, or else making "wrap" a method of a factory object whose
destructor will delete all of the dynamically allocated objects returned
by wrap.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Oct 25 '08 #19

P: n/a
On 2008-10-25 14:44:59 -0400, "Fraser Ross" <z@zzzzzz.comsaid:
"Pete Becker"
Yes. Two string literals with the same sequence of characters can be
at
>the same address or at different addresses. So:

template <const char *class C
{
};

C<"asdf"c0;
C<"asdf"c1 = c0;

c0 and c1 could be the same type or they could be different types, so
in some cases the initialization of c1 would fail, and in others it
would succeed.

That could be the programmers responsibility.
Well, okay. But most programmers probably don't want to be responsible
for determining when two identical string literals are merged into one
and when they aren't. It depends on the compiler and on the compiler's
option settings.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Oct 25 '08 #20

P: n/a
On 23 ÏËÔ, 06:58, cplusle...@gmail.com wrote:
Hi,
š š šI have a local class inside a function template. I am able to wrap
any type in my local class. Is it legal C++? What type of class is
Local? šIs it a class template or regular class?
š š šThanks in advance.
Using local classes as template parameters is prohibited in current C+
+ standard. There's a proposal for C++0x - N2657.

Passing local classes as template parameters known to work in MSVC.
However, doing such thing in an inline function may cause link error.

Local is regular class, there's no such thing as local template.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Oct 25 '08 #21

P: n/a

<cp********@gmail.comwrote in message
news:e7**********************************@t54g2000 hsg.googlegroups.com...
Hi,
I have a local class inside a function template. I am able to wrap
any type in my local class. Is it legal C++? What type of class is
Local? Is it a class template or regular class?
Thanks in advance.
--dhina
---------------------------------------------------------------------------------------------------------------------------------------------
class Foo
{
public:
virtual ~Foo() {}
virtual void print() = 0;
};

template< typename T >
Foo* wrap(const T& t)
{
class Local : public Foo
{
public:
Local(const T& t):val_(t) { }
void print()
{
cout << "In Local::print()" << val_ << endl;
}
private:
T val_;
};
return new Local(t);
}

int main(void)
{
int x = 50;
Foo* ptr = wrap(x);
ptr->print();
^^^^^^^^^^^^^^^^^^^

delete ptr;

std::string s("wrap");
ptr = wrap(s);
ptr->print();
^^^^^^^^^^^^^^^^^^^

delete ptr;

}

You have memory leaks. BTW, excuse me for being so dense, but what
advantages does this technique have over something like:
__________________________________________________ __________________
#include <iostream>
#include <string>
struct foo_impl {
virtual ~foo_impl() = 0;
virtual void print() const = 0;
};
foo_impl::~foo_impl() {
std::cout << "In (" << this <<
")->foo_impl::~foo_impl()" << std::endl;
}
typedef foo_impl const& foo;
template<typename T>
class wrapper : public foo_impl {
T m_obj;

void print() const {
std::cout << "In (" << this <<
")->wrapper<T>::print - " << m_obj << std::endl;
}

public:
wrapper(T const& obj)
: m_obj(obj) {
}

~wrapper() {
std::cout << "In (" << this <<
")->wrapper<T>::~wrapper() - " << m_obj << std::endl;
}
};
template<typename T>
static wrapper<T>
wrap(T const& obj) {
return wrapper<T>(obj);
}
int main(void) {
int x = 5;
foo fx = wrap(x);
fx.print();
std::string s("wrap");
foo fs = wrap(s);
fs.print();
return 0;
}
__________________________________________________ __________________


Thanks.

Oct 26 '08 #22

P: n/a

"Chris M. Thomasson" <no@spam.invalidwrote in message
news:P%******************@newsfe07.iad...
>
<cp********@gmail.comwrote in message
news:e7**********************************@t54g2000 hsg.googlegroups.com...
>Hi,
I have a local class inside a function template. I am able to wrap
any type in my local class. Is it legal C++? What type of class is
Local? Is it a class template or regular class?
Thanks in advance.
--dhina
---------------------------------------------------------------------------------------------------------------------------------------------
[...]
>}


You have memory leaks. BTW, excuse me for being so dense, but what
advantages does this technique have over something like:
__________________________________________________ __________________
[...]
__________________________________________________ __________________
Are you going for delegates? If so, well, one can easily modify ScopeGuard:

http://www.ddj.com/cpp/184403758

to return dynamically created objects than can be effectively used as fairly
efficient delegates/futures.

Oct 26 '08 #23

P: n/a

<cp********@gmail.comwrote in message
news:e7**********************************@t54g2000 hsg.googlegroups.com...
Hi,
I have a local class inside a function template. I am able to wrap
any type in my local class. Is it legal C++? What type of class is
Local? Is it a class template or regular class?
Thanks in advance.
--dhina
---------------------------------------------------------------------------------------------------------------------------------------------
class Foo
{
public:
virtual ~Foo() {}
virtual void print() = 0;
};

template< typename T >
Foo* wrap(const T& t)
{
class Local : public Foo
{
public:
Local(const T& t):val_(t) { }
void print()
{
cout << "In Local::print()" << val_ << endl;
}
private:
T val_;
};
return new Local(t);
}

int main(void)
{
int x = 50;
Foo* ptr = wrap(x);
ptr->print();
^^^^^^^^^^^^^^^^^^^

delete ptr;

std::string s("wrap");
ptr = wrap(s);
ptr->print();
^^^^^^^^^^^^^^^^^^^

delete ptr;

}

You have memory leaks. BTW, excuse me for being so dense, but what
advantages does this technique have over something like:
__________________________________________________ __________________
#include <iostream>
#include <string>
struct foo_impl {
virtual ~foo_impl() = 0;
virtual void print() const = 0;
};
foo_impl::~foo_impl() {
std::cout << "In (" << this <<
")->foo_impl::~foo_impl()" << std::endl;
}
typedef foo_impl const& foo;
template<typename T>
class wrapper : public foo_impl {
T m_obj;

void print() const {
std::cout << "In (" << this <<
")->wrapper<T>::print - " << m_obj << std::endl;
}

public:
wrapper(T const& obj)
: m_obj(obj) {
}

~wrapper() {
std::cout << "In (" << this <<
")->wrapper<T>::~wrapper() - " << m_obj << std::endl;
}
};
template<typename T>
static wrapper<T>
wrap(T const& obj) {
return wrapper<T>(obj);
}
int main(void) {
int x = 5;
foo fx = wrap(x);
fx.print();
std::string s("wrap");
foo fs = wrap(s);
fs.print();
return 0;
}
__________________________________________________ __________________


Thanks.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Oct 26 '08 #24

P: n/a

"Chris M. Thomasson" <no@spam.invalidwrote in message
news:P%******************@newsfe07.iad...
>
<cp********@gmail.comwrote in message
news:e7**********************************@t54g2000 hsg.googlegroups.com...
>Hi,
I have a local class inside a function template. I am able to wrap
any type in my local class. Is it legal C++? What type of class is
Local? Is it a class template or regular class?
Thanks in advance.
--dhina
---------------------------------------------------------------------------------------------------------------------------------------------
[...]
>}


You have memory leaks. BTW, excuse me for being so dense, but what
advantages does this technique have over something like:
__________________________________________________ __________________
[...]
__________________________________________________ __________________
Are you going for delegates? If so, well, one can easily modify ScopeGuard:

http://www.ddj.com/cpp/184403758

to return dynamically created objects than can be effectively used as fairly
efficient delegates/futures.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Oct 26 '08 #25

P: n/a
Chris M. Thomasson wrote:
<cp********@gmail.comwrote
> I have a local class inside a function template. I am able to wrap
any type in my local class. Is it legal C++? What type of class is
Local? Is it a class template or regular class?
<snipCode to define an abstract interface, and a function template
whose instantiations return pointers to dynamically allocated instances
of local classes implementing the interface. (Whew.) </snip>
You have memory leaks. BTW, excuse me for being so dense,
You're excused. ;)
but what
advantages does this technique have over something like:
struct foo_impl {
virtual ~foo_impl() = 0;
virtual void print() const = 0;
};
Boo. A class called foo_impl with only pure virtual methods is a
contradiction in terms.
typedef foo_impl const& foo;
Boo. A reference type whose name does not end in "ref" or "reference"
is a debugging mess waiting to happen. Just wait until some unwary
client tries to create a vector<foo>.

<snipCode that replaces the OP's local classes with instantiations of
a template that all derive from the common interfaces, and avoids the
OP's dynamic allocation by returning the instances by value (and
requiring the client code to bind those temporary instances to
const-references). </snip>

Boo to your deprecated use of static. And in what way is std::endl
superior to '\n'? If there's really a need to flush std::cout's buffer,
and if the code might run on a platform where '\n' doesn't cause that to
happen anyway, wouldn't it be clearer to call flush directly?
Furthermore, boo to main(void), which is in no way clearer than main().

Bravo to your replacement of dynamic allocation with automatic. Still,
your code does not achieve the same thing as the OP's:

(1) Your client can't call non-const methods of foo, whereas the OP's
client can. You've changed the interface's only method to be const, but
that changes the meaning, and breaks any subclasses not included in the
posted code.

(2) You can't treat pretend a reference is an object for anything other
than trivial use. You can't have collections of them, for example.

(3) You can't pass your wrappers any farther up the stack (in contrast
to the OP's pointers to free store). For example:

foo rewrap(int i) { return wrap(i); }

int main() {

// ok
foo f = wrap(5); f.print();

// run-time error: pure virtual method called
foo g = rewrap(5); g.print();

return 0;
}

(4) I foresee type-slicing problems. I'm not sure where they're hiding
yet, but I can smell them from here.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Oct 27 '08 #26

P: n/a
On 25 Okt., 17:28, "Fraser Ross" <z...@zzzzzz.comwrote:
In the standards example below neither constructor is accessible and
only one is used.

template<class T, char* pclass X {
X();
X(const char* q) { *}};

X<int, "Studebaker"x1; // error: string literal as template-argument
char p[] = "Vivisectionist";
X<int,px2; // OK

Fraser.
You need external linkage:

char const* Studebaker = "Studebaker";
X<int, "Studebaker"x1; // no error

I took the liberty to assume you intended to use a char const* as the
nontype parameter. If not your code looks rather suspicious.

/Peter
Oct 27 '08 #27

P: n/a
"peter koch"
>You need external linkage:
I was asking why its necessary. Pete gave a reason.

Fraser.
Oct 28 '08 #28

P: n/a

"Jeff Schwab" <je**@schwabcenter.comwrote in message
news:_b******************************@giganews.com ...
Chris M. Thomasson wrote:
><cp********@gmail.comwrote
>> I have a local class inside a function template. I am able to wrap
any type in my local class. Is it legal C++? What type of class is
Local? Is it a class template or regular class?

<snipCode to define an abstract interface, and a function template
whose instantiations return pointers to dynamically allocated instances
of local classes implementing the interface. (Whew.) </snip>
>You have memory leaks. BTW, excuse me for being so dense,
[...]

Bravo for your comments; thank you. I am a C programmer, not C++. Oh SHI%!

[BTW, this got rejected on comp.lang.c++.moderated!!!]
Oct 31 '08 #29

This discussion thread is closed

Replies have been disabled for this discussion.