Conversion from 'myItem*' to non-scalar type 'myItem' requested


I have this C++ code:

#include <iostream>
using namespace std;
struct MyItem
{
  int value;
  MyItem* nextItem;
};

int main() {
    MyItem item = new MyItem;
    return 0;
}

And I get the error:

error: conversion from `MyItem*' to non-scalar type `MyItem' requested

Compiling with g++. What does that mean? And what's going on here?


Answers:


Try:

MyItem * item = new MyItem;

But do not forget to delete it after usage:

delete item;