Passing template class by reference
Jonathan Wakely
jwakely.gcc@gmail.com
Wed Feb 3 23:12:00 GMT 2010
On 3 February 2010 23:07, Minhaj Ahmed wrote:
> How do you pass a template class object by reference? As an example:
This is off-topic for this mailing list, please take your question to
the gcc-help mailing list or a forum about C++
> Say we have a namespace util and
>
> Namespace NewName
> {
> Class A
> {
> SomeRoutine(util::CSomeUtilClass<CDataWrapperClass>
> &msg);
This function is missing a return type.
> };
> }
>
> Now when I call this method in a cpp file gcc complains that
> "error: with
> NewName::A::SomeRoutine(util::CSomeUtilClass<CDataWrapperClass>&)'
> And
> Error: no matching function for call to
> 'NewName::A::SomeRoutine(util::CSomeUtilClass<CDataWrapperClass>&)'
>
> Any idea how I can get around this? I can remove the '&' from method
> and have it compile just fine! Any help would be greatly appreciated...
I would guess you're passing a temporary or a const obejct which
cannot bind to the non-const reference.
> Also I've another strange problem with nested classes:
>
> So let say we have
>
> Class SemaphoreC
> {
> ...
> };
>
>
> Class data
> {
> ...
> };
>
> Namespace util
> {
>
> tempate <class T>
> Class SmartPtr
> {
> ...
> };
>
>
> template <class T>
> class someTemplate
> {
> Public:
> GetSem(){return m_sem);
Again, you're missing a return type - this isn't valid C++.
All the uppercase letters don't help either.
> Private:
> SemaphoreC m_sem;
> };
>
> }
>
> class A
> {
> Class Nested
> {
> Class A *a_ptr;
> };
>
> Private:
> TrytogetSem();
> util::someTemplate< util::SmartPtr<data> > var;
> };
>
> Now when the GetSem is called from A::TrytogetSem() ie.
>
> A::TrytogetSem()
> {
> Declared in class Nested declared in class A
> member of someTemplate
> | |
> |
> | |
> |
> SemaphoreC s = a_ptr-> var.
> GetSem();
>
> }
>
> And gcc complains that it's unable to convert void * to LONG? I can
> declare 's' as void * and the error disappears
I can't read the code above, but as I said, please ask this in a more
appropriate forum.
Jonathan
More information about the Libstdc++
mailing list