Hi, I'm supposed to make a class called Auto with the make model type, etc. I am supposed to have a data member named nextAuto with type auto. This however is giving me an issue as the compiler gives me an error that says auto not allowed in non-static class member.Any ideas of how to fix this?
THis is in my .h file
#ifndef AUTO_H
#define AUTO_H
#include <iostream>
#include<string.h>
using namespace std;
You can't use the type of what you're defining in its own definition - that's why you get the incomplete type error. The issue is that the compiler doesn't know at that point the size of the type. You can only use a pointer to the type of what is being defined (the size of a pointer is known by the compiler). That's why Auto nextAuto is wrong, but Auto* nextAuto is OK - as now nextAuto is a pointer.
What you're saying doesn't make a lot of sense; you're making a class that represents a car ( a class called Auto with the make model type, etc.), and the car is to contain a car (supposed to have a data member named nextAuto with type auto), and that car is to contain a car, and that car is to contain a car, and that car is to contain a car, and that car is to contain a car, and that ... you've described some kind of object that contains infinite objects, containing infinite objects.
What do your instructions actually say you have to do? Because what you've described to us is impossible. What are the exact words of your assignment. Exact words.
class Auto{
//your current code without the `nextAuto' line
};
class List_Auto{
class Node_Auto{
Auto data;
Auto *next;
};
//your generic list implementation using Node_Auto
};
limit the responsibilities of your classes.
An auto is not a collection of autos.