Jump to content

  • Log In with Google      Sign In   
  • Create Account

Returning Templates


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Dæmin   Members   -  Reputation: 128

Like
Likes
Like

Posted 06 August 2001 - 06:14 PM

Heya, I''m having a serious problem here, I try to return a template class from a function and it all goes to hell. Basically I am trying to do this:
TArray& ListFiles( /* blah */ );
or this:
int ListFiles( TArray* /* blah */ );
 
and none of them return the Array Object properly. I.e. its all fuX0rd... I''m using MSVC 6.0 BTW and so I am wondering if this is a compiler bug, template bug, or that I have to do something special (like make a good Copy constructor?). -Cheers. P.S. I''ve already got ideas to make a wrapper class for TArray and my string class works okay.

Sponsor:

#2 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 06 August 2001 - 06:31 PM

The problem is with your code; it''s not a compiler bug.

Try something like this:


template
TArray& ListFiles(/* blah */) {...}

// Or...

template
int ListFiles(TArray *t, /* blah */);

// Note: you may have to call your function like this:
// TArray t = ListFiles(/* blah */);


Hope this helps.

#3 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 06 August 2001 - 06:35 PM

Sorry.... Let''s try this again, shall we?

template < typename T >
TArray< T >& ListFiles(/* blah */) {...}

// Or...

template < typename T >
int ListFiles(TArray< T > *t, /* blah */);

// Note: you may have to call your function like this:
// TArray< int > t = ListFiles< int >(/* blah */);

#4 Dæmin   Members   -  Reputation: 128

Like
Likes
Like

Posted 07 August 2001 - 02:31 AM

Well the thing is that TArray, and BString are already defined classes, and that particular function is defined within another class.
i.e.

template class TArray { ... };
// and
class BString { ... };
// etc


Strickly speaking

TArray&

is just the return type.

And the way that I''m calling it is like so:


TArray Stuff = Something.ListFiles(/* blah */);


It still stuffs up then, so I am really wondering if its got anything to do with the = operator. Its just wierd...

#5 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 07 August 2001 - 09:03 PM

It appears your templates got cut off (because this board seems to interpret angular brackets as HTML tags).

Anyway, you can''t do something like this:

TArray t = ...;

You have to give TArray a type. So it''d be like this:

  
TArray<int> t = Something.ListFiles(/* blah */);


You have to specify a type for the template class when you call it.

Also, if the return type is "TArray&" (and not "TArray< T >&"), and TArray is a template then that code is probably wrong. It needs to look like:

template< typename T >
TArray< T >& Something::ListFiles(/* blah */) { ... }

#6 Dæmin   Members   -  Reputation: 128

Like
Likes
Like

Posted 09 August 2001 - 02:03 AM

Yeah it got cut off, basically I have done everything that you have suggested it before, (I''m not that much of an idiot you know).

Oh well I''ll just make a wrapper class or something.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS