How to implement type Auto?

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;

class Auto

{
public:

Auto(string model,string make,string type,int chassis);
string getMake();
void setmake(string makee);
string getModel();
void setModel(string m);
string getType();
void setType(string ty);
void setChassisNumber(int chassis);
int getChassisNumber();
private:

int chassisNum;
string make;
string model;
string type;
auto nextAuto;


};

Last edited on
Here:
1
2
    auto nextAuto;
};

You meant to write 'Auto', not 'auto' (or, more likely, 'Auto *'). Lowercase auto is a reserved keyword in C++ with a specific meaning.


but if i put Auto nextAuto;

i get the error field has incomplete type 'Auto'
What can I do to fix this?
Last edited on
or, more likely, 'Auto *'
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.
I suspect it's an attempt to have a forward linked list of Auto.
1
2
3
4
5
6
7
8
9
10
11
12
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.
Registered users can post here. Sign in or register to post.