$("a").click(function() {
pushOrRemove($(this).data('value'), $(this).data('key'))
});
function pushOrRemove(value, array_key) {
// get the variable you store the json in
var $storedValues = $('[data-stored-values]');
// if the json is not set, default to an empty object
var attribute_values = JSON.parse($storedValues.val() || '{}');
// if the key is not in the object yet, defaultto an empty array
attribute_values[array_key] = attribute_values[array_key] || [];
// get the index of the value
var indexOfValue = attribute_values[array_key].indexOf(value);
// if the index is -1, it's not in there, so add
if (indexOfValue < 0) {
attribute_values[array_key].push(value);
} else {
// the index was 0 or more, so remove it
attribute_values[array_key].splice(indexOfValue, 1);
}
// update the stored json for the next interaction
$storedValues.val(JSON.stringify(attribute_values));
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="#" data-value="10" data-key="20">Click</a>
<a href="#" data-value="20" data-key="20">Click</a>
<a href="#" data-value="30" data-key="20">Click</a>
<a href="#" data-value="10" data-key="30">Click</a>
<a href="#" data-value="20" data-key="30">Click</a>
<a href="#" data-value="30" data-key="30">Click</a>
<input type="text" data-stored-values>
Определить конструктор для A ПОСЛЕ определения структуры B.
Выражение c-> i
разыменовывает указатель на struct A :: B
, поэтому полное определение должно быть видно в этой точке программы.
Самое простое решение - сделать конструктор из A
не встроенным и предоставить тело для него после определения struct A :: B
.
Это хороший пример того, почему вы хотите отделить определения от объявлений. Вам нужно изменить порядок вещей так, чтобы конструктор A :: A ()
был определен после определения struct A :: B
.
class A
{
struct B;
B* c;
A();
};
struct A::B
{
int i;
};
A::A() { c->i; }
int main()
{
return 0;
}