kralco626 kralco626 - 1 year ago 110
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 Source


MyItem * item = new MyItem;

But do not forget to delete it after usage:

delete item;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download