Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Can't copy TSharedPtr because of const incompatibility of underlying pointer

I keep getting the same compile error in multiple places when trying to copy TSharedPtr's around. That error being of the form:

 Error    1    error C2440: 'initializing' : cannot convert from 'NonexpirableStatModValue *const ' to 'Stats::NonexpirableStatModValue *'

One example is that I have an array of shared pointers, declared as:

 TArray< TSharedPtr<class NonexpirableStatModValue> > m_mods;

And I try to pass an element of that array in to a function like so:


Where that function signature is of the form:

 void    AddMod(const TSharedPtr<NonexpirableStatModValue> pMod)

It seems that most of these instances have to do with having a TArray of shared pointers, and probably due to the fact that the [] operator of TArray returns a reference, which I suppose is automatically const when it's an rvalue, but I'm not sure I'm supposed to be doing in this instance. Are you just not allowed to have arrays of shared pointers?

Product Version: Not Selected
more ▼

asked Sep 20 '14 at 09:41 AM in C++ Programming

avatar image

121 7 13 20

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Ahh, nevermind, I figured it out. It has to do with the namespace my classes resided in, and how I didn't specify the namespace for the type in the array declaration. I.e. TArray< TSharedPtr > m_mods; instead of

 TArray< TSharedPtr<class Stats::NonexpirableStatModValue> > m_mods;

The difference in const-ness was a red herring.

more ▼

answered Sep 20 '14 at 07:42 PM

avatar image

121 7 13 20

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question