# Help with basic templating of Point\<int\>?

**URL:** <https://forum.juce.com/t/help-with-basic-templating-of-point-int/29228>\
**Category:** Getting Started\
**Created:** [August 31, 2018, 11:41pm UTC](https://forum.juce.com/t/help-with-basic-templating-of-point-int/29228 "2018-08-31T23:41:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lob](https://avatars.discourse-cdn.com/v4/letter/l/ecae2f/32.png) [@lob](https://forum.juce.com/u/lob)\
**Post date:** [August 31, 2018, 11:41pm UTC](https://forum.juce.com/t/help-with-basic-templating-of-point-int/29228/1 "2018-08-31T23:41:20Z")

</div>

Hi,  
I am no programmer and I don’t know any. I can’t get the following addition to work in varaiant.h. Any help would be much appreciated. I have tried typedefing

```
point<int>

```

, changing

```
template <typename Type> 

```

to

```
template <class Type>

```

and many other options. No luck.  
Thank you

Here is the code I am having difficulty with

```
    template <> struct VariantConverter<Point<int>>
    {
        static Point<int> fromVar (const var& v)
        {
            return Point<int>
            (
             { v[0].operator int(), v[1].operator int() }
             );
        }
        static var toVar (const Point<int>& p)
        {
            return Array<var>(
                               { p.getX(), p.getY() }
                               );
        }
    };
```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [September 1, 2018, 8:11am UTC](https://forum.juce.com/t/help-with-basic-templating-of-point-int/29228/2 "2018-09-01T08:11:17Z")

</div>

perhaps something like

```auto
template <>
struct VariantConverter<Point<int>>
{
    static Point<int> fromVar (const var& v) { return { v[0], v[1] }; }
    static var toVar (const Point<int>& p) { return Array<var> { p.x, p.y }; }
};

```

---

<div class="post-metadata">

**Author:** ![lob](https://avatars.discourse-cdn.com/v4/letter/l/ecae2f/32.png) [@lob](https://forum.juce.com/u/lob)\
**Post date:** [September 1, 2018, 9:39am UTC](https://forum.juce.com/t/help-with-basic-templating-of-point-int/29228/3 "2018-09-01T09:39:10Z")

</div>

Hi Jules,  
I am taking my day off, but that didn’t work for me. I will try reinstalling JUCE tomorrow. Maybe I have messed up the JUCE code somewhere.  
Thank you.

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [September 1, 2018, 11:49am UTC](https://forum.juce.com/t/help-with-basic-templating-of-point-int/29228/4 "2018-09-01T11:49:18Z")

</div>

> [@lpb](#):
>
> that didn’t work for me.

It would be useful if you explained how it didn’t work for you? (Show your code that tries using it.)

---

<div class="post-metadata">

**Author:** ![lob](https://avatars.discourse-cdn.com/v4/letter/l/ecae2f/32.png) [@lob](https://forum.juce.com/u/lob)\
**Post date:** [September 1, 2018, 12:11pm UTC](https://forum.juce.com/t/help-with-basic-templating-of-point-int/29228/5 "2018-09-01T12:11:02Z")

</div>

Both versions working now. I haven’t changed anything yet. Was getting two Xcode errors despite many variations. I was not implementing any instances yet.  
The errors were

/Tools/JUCE/modules/juce\_core/containers/juce\_Variant.h:41:18: Expected unqualified-id

and

/Tools/JUCE/modules/juce\_core/containers/juce\_Variant.h:343:46: Expected ‘\>’

Not sure what that was, but I am very happy.  
Thank you Jules and Xenakios.

---

<div class="post-metadata">

**Author:** ![lob](https://avatars.discourse-cdn.com/v4/letter/l/ecae2f/32.png) [@lob](https://forum.juce.com/u/lob)\
**Post date:** [September 2, 2018, 3:37pm UTC](https://forum.juce.com/t/help-with-basic-templating-of-point-int/29228/6 "2018-09-02T15:37:49Z")

</div>

Hi,  
Once I test

```
    CachedValue<juce::Point<int>> pointTest;

```

the errors start again. The code assumes one get an

```
Array<var>

```

from a

```
var& 

```

The code doesn’t appear to work even with a further templated passing of

```
property.getArray()

```

from cached\_value.h.

Anyone have any tricky thoughts on how to make this less tricky. Once one can save Point to a cachedValue, then one can translate the principle to further types like Rectangles. This will make it easy to save these types to valuetree via linked cachedValues, which has a lot of uses.  
Thank you

---

<div class="post-metadata">

**Author:** ![lob](https://avatars.discourse-cdn.com/v4/letter/l/ecae2f/32.png) [@lob](https://forum.juce.com/u/lob)\
**Post date:** [September 3, 2018, 4:12am UTC](https://forum.juce.com/t/help-with-basic-templating-of-point-int/29228/7 "2018-09-03T04:12:13Z")

</div>

# [CachedValue referTo not working](https://forum.juce.com/t/cachedvalue-referto-not-working/25219) has a better idea.

They use StringArray rather than Array.

---

<div class="post-metadata">

**Author:** ![lob](https://avatars.discourse-cdn.com/v4/letter/l/ecae2f/32.png) [@lob](https://forum.juce.com/u/lob)\
**Post date:** [September 4, 2018, 6:49am UTC](https://forum.juce.com/t/help-with-basic-templating-of-point-int/29228/8 "2018-09-04T06:49:15Z")

</div>

Hi,  
Programming has those nightmare days all blurred into one. Trying to get the basic cachedValue working has been part of a little nightmare. I am using Dave’s variant converter.

```
    template <> struct VariantConverter<Colour>
    {
        static Colour fromVar (const var& v)
        {
            return Colour::fromString ( v.toString() );
        }
        static var toVar (const Colour& c)
        {
            return c.toString();
        }
    };

```

with

```
     CachedValue<Colour> test;
     Colour colourTest;
     ValueTree tempColourTree;

```

and

```
     colourTest = Colours::black;
     tempColourTree = valueTree.getChildWithName("colourTest");
     test.referTo (tempColourTree, "Colour", nullptr);
     test.setValue (colourTest, nullptr);

```

Am I missing something?  
Thank you
