kralco626 kralco626 - 24 days ago 12
C++ Question

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?

Answer

Try:

MyItem * item = new MyItem;

But do not forget to delete it after usage:

delete item;
Comments