<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Can&#x27;t figure out why this isnt working ( smart pointer casting )]]></title><description><![CDATA[<p>Hi I wrote to following in an attempt to create a flexible container , that can store multiple types of objects at the same time.( idea from a post on SFML forum ) But I can't figure out why it isn't running, am I beeing stupid again ? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
IProperty.hpp :</p>
<pre><code>#ifndef IPROPERTY_HPP
#define IPROPERTY_HPP

#include &lt;string&gt;

class IProperty
{
	public:
		IProperty(std::string name, const std::string id);
		virtual ~IProperty();

		const std::string   getId()  { return id_; }
		      std::string getName(){ return name_; }

			  virtual void updateProperty() = 0;

	protected:
	private:
		const std::string   id_;
		      std::string name_;
};

#endif
</code></pre>
<p>IProperty.cpp :</p>
<pre><code>#include &quot;IProperty.hpp&quot;

IProperty::IProperty(std::string name, const std::string id)
	:id_(id), name_(name)
{}

IProperty::~IProperty()
{}
</code></pre>
<p>TProperty.hpp :</p>
<pre><code>#ifndef TPROPERTY_HPP
#define TPROPERTY_HPP

#include &lt;string&gt;
#include &lt;typeinfo&gt;

#include &quot;IProperty.hpp&quot;

template &lt;class T&gt;
class TProperty : public IProperty
{
	public:
		TProperty(const std::string id) : IProperty(typeid(T).name(), id){}

		   T getValue       (){ return value_; }
		   void setValue(T value){ value_ = value; }

		   void updateProperty() override {}

	protected:
	private:
		T value_;
};

#endif
</code></pre>
<p>PropertyManager.hpp :</p>
<pre><code>#ifndef PROPERTY_MANAGER
#define PROPERTY_MANAGER

#include &lt;map&gt;
#include &lt;memory&gt;
#include &lt;string&gt;

#include &quot;IProperty.hpp&quot;
#include &quot;TProperty.hpp&quot;

class PropertyManager
{
	public:
		PropertyManager();
		virtual ~PropertyManager();

		template &lt; class T &gt;
		T getPropertyValue(const std::string id){
			if (properties_.find(id) != properties_.end()){
				if (properties_.at(id)-&gt;getName() == typeid(T).name()){
					return std::dynamic_pointer_cast&lt;TProperty&lt;T&gt;&gt;(properties_.at(id))-&gt;getValue();
				}
			}
		}

		template &lt; class T &gt;
		void setPropertyValue(const std::string id, T value){
			if (properties_.find(id) != properties_.end()){
				if (properties_.at(id)-&gt;getName() == typeid(T).name()){
					std::dynamic_pointer_cast&lt;TProperty&lt;T&gt;&gt;(properties_.at(id))-&gt;setValue(value);
				}
			}
		}

		template &lt; class T &gt; 
		void addProperty(const std::string id, T value){
			std::cout &lt;&lt; value &lt;&lt; std::endl;

			if (properties_.find(id) == properties_.end()){
				if (properties_.at(id)-&gt;getName() == typeid(T).name()){
					properties_.emplace(id, std::make_shared &lt; TProperty&lt;T&gt;(id));
					setPropertyValue(id, value);
				}
			}
		}

	protected:
	private:
		std::map&lt;std::string, std::shared_ptr&lt;IProperty&gt;&gt; properties_;
};

#endif
</code></pre>
<p>PropertyManager.cpp :</p>
<pre><code>#include &quot;PropertyManager.hpp&quot;

PropertyManager::PropertyManager()
{}

PropertyManager::~PropertyManager()
{}
</code></pre>
<p>Im Voraus schon einmal danke <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/336846/can-t-figure-out-why-this-isnt-working-smart-pointer-casting</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 20:35:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/336846.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 20 Feb 2016 02:31:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Can&#x27;t figure out why this isnt working ( smart pointer casting ) on Sat, 20 Feb 2016 02:31:12 GMT]]></title><description><![CDATA[<p>Hi I wrote to following in an attempt to create a flexible container , that can store multiple types of objects at the same time.( idea from a post on SFML forum ) But I can't figure out why it isn't running, am I beeing stupid again ? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
IProperty.hpp :</p>
<pre><code>#ifndef IPROPERTY_HPP
#define IPROPERTY_HPP

#include &lt;string&gt;

class IProperty
{
	public:
		IProperty(std::string name, const std::string id);
		virtual ~IProperty();

		const std::string   getId()  { return id_; }
		      std::string getName(){ return name_; }

			  virtual void updateProperty() = 0;

	protected:
	private:
		const std::string   id_;
		      std::string name_;
};

#endif
</code></pre>
<p>IProperty.cpp :</p>
<pre><code>#include &quot;IProperty.hpp&quot;

IProperty::IProperty(std::string name, const std::string id)
	:id_(id), name_(name)
{}

IProperty::~IProperty()
{}
</code></pre>
<p>TProperty.hpp :</p>
<pre><code>#ifndef TPROPERTY_HPP
#define TPROPERTY_HPP

#include &lt;string&gt;
#include &lt;typeinfo&gt;

#include &quot;IProperty.hpp&quot;

template &lt;class T&gt;
class TProperty : public IProperty
{
	public:
		TProperty(const std::string id) : IProperty(typeid(T).name(), id){}

		   T getValue       (){ return value_; }
		   void setValue(T value){ value_ = value; }

		   void updateProperty() override {}

	protected:
	private:
		T value_;
};

#endif
</code></pre>
<p>PropertyManager.hpp :</p>
<pre><code>#ifndef PROPERTY_MANAGER
#define PROPERTY_MANAGER

#include &lt;map&gt;
#include &lt;memory&gt;
#include &lt;string&gt;

#include &quot;IProperty.hpp&quot;
#include &quot;TProperty.hpp&quot;

class PropertyManager
{
	public:
		PropertyManager();
		virtual ~PropertyManager();

		template &lt; class T &gt;
		T getPropertyValue(const std::string id){
			if (properties_.find(id) != properties_.end()){
				if (properties_.at(id)-&gt;getName() == typeid(T).name()){
					return std::dynamic_pointer_cast&lt;TProperty&lt;T&gt;&gt;(properties_.at(id))-&gt;getValue();
				}
			}
		}

		template &lt; class T &gt;
		void setPropertyValue(const std::string id, T value){
			if (properties_.find(id) != properties_.end()){
				if (properties_.at(id)-&gt;getName() == typeid(T).name()){
					std::dynamic_pointer_cast&lt;TProperty&lt;T&gt;&gt;(properties_.at(id))-&gt;setValue(value);
				}
			}
		}

		template &lt; class T &gt; 
		void addProperty(const std::string id, T value){
			std::cout &lt;&lt; value &lt;&lt; std::endl;

			if (properties_.find(id) == properties_.end()){
				if (properties_.at(id)-&gt;getName() == typeid(T).name()){
					properties_.emplace(id, std::make_shared &lt; TProperty&lt;T&gt;(id));
					setPropertyValue(id, value);
				}
			}
		}

	protected:
	private:
		std::map&lt;std::string, std::shared_ptr&lt;IProperty&gt;&gt; properties_;
};

#endif
</code></pre>
<p>PropertyManager.cpp :</p>
<pre><code>#include &quot;PropertyManager.hpp&quot;

PropertyManager::PropertyManager()
{}

PropertyManager::~PropertyManager()
{}
</code></pre>
<p>Im Voraus schon einmal danke <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2487946</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2487946</guid><dc:creator><![CDATA[xxXLukas97Xxx]]></dc:creator><pubDate>Sat, 20 Feb 2016 02:31:12 GMT</pubDate></item><item><title><![CDATA[Reply to Can&#x27;t figure out why this isnt working ( smart pointer casting ) on Sat, 20 Feb 2016 03:50:49 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">template &lt; class T &gt;
        void addProperty(const std::string id, T value){
            std::cout &lt;&lt; value &lt;&lt; std::endl;

            if (properties_.find(id) == properties_.end()){
                if (properties_.at(id)-&gt;getName() == typeid(T).name()){
</code></pre>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /><br />
<img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/27a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--right_arrow"
      title=":arrow_right:"
      alt="➡"
    /> zuviel c&amp;p <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/26a0.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--warning"
      title=":warning:"
      alt="⚠"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2487948</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2487948</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sat, 20 Feb 2016 03:50:49 GMT</pubDate></item></channel></rss>