issue with using aliases: syntax error: missing ';' before '*'

Feb 17, 2020 at 5:43am
I have two classes unsorted.h and a child class Appointment.h. They Should take input in the form: 1/23/1999 Coffee

I want to use Appointment as ItemType but when I use typedef to do so, I get compilation errors. The below are a bunch of errors caused since it doesn't accept ItemType as an alias.

I know the issue has something to do with circular headers and the solution can be something using forward declarations. But I have tried a lot of different combinations and nothing seems to solve the compilation errors.


Errors:
```
Severity Code Description Project File Line Suppression State
Error C2143 syntax error: missing ';' before '*' Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\unsorted.h 20
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\unsorted.h 20
Error C2238 unexpected token(s) preceding ';' Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\unsorted.h 20
Error C2143 syntax error: missing ';' before '*' Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\unsorted.h 33
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\unsorted.h 33
Error C2334 unexpected token(s) preceding '{'; skipping apparent function body Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\unsorted.h 33
Error C3867 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str': non-standard syntax; use '&' to create a pointer to member Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\appointment.cpp 28
Error C3867 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str': non-standard syntax; use '&' to create a pointer to member Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\appointment.cpp 29
Error C3867 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str': non-standard syntax; use '&' to create a pointer to member Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\appointment.cpp 30
Error C3867 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str': non-standard syntax; use '&' to create a pointer to member Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\appointment.cpp 34
Error C3867 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str': non-standard syntax; use '&' to create a pointer to member Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\appointment.cpp 35
Error C3867 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str': non-standard syntax; use '&' to create a pointer to member Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\appointment.cpp 36
Error C2039 'item_arr': is not a member of 'Appointment' Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\appointment.cpp 59
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\appointment.h 13
Error C2146 syntax error: missing ';' before identifier 'ItemType' Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\appointment.h 13
Error C2371 'Appointment': redefinition; different basic types Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\appointment.h 14
Error C2504 'UnsortedType': base class undefined Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\appointment.h 15
Error C2143 syntax error: missing ';' before '*' Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\unsorted.h 20
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\unsorted.h 20
Error C2238 unexpected token(s) preceding ';' Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\unsorted.h 20
Error C2143 syntax error: missing ';' before '*' Lab3 c:\users\victornath\desktop\labs\datastruc\lab3\lab3\unsorted.h 33
```



Unsorted.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  
#ifndef LAB3_H
#define LAB3_H 
#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
#include "Appointment.h"
#include <vector>


using namespace std;
class Appointment; // forward declaration

class UnsortedType
{
    protected:
		int length = 0;
		int size;
	    //string *item_arr; //dynamic array of items
		ItemType *item_arr;
		//ItemType temp_obj;

	
    public:
		UnsortedType();
		UnsortedType(int num);
		UnsortedType(const UnsortedType& arg); // copy constructor
		UnsortedType& operator = (const UnsortedType& arg); // assignment operator
		~UnsortedType(); //destructor
		bool isFull();
		void PutItem(string s);
		int getLength() const { return length; };
	    ItemType* getitem_arr() const { return item_arr; };

};



#endif



Appointment.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef LAB3_H2
#define LAB3_H2
#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
#include "unsorted.h"
#include <vector>


using namespace std;

typedef Appointment ItemType;
class Appointment : public UnsortedType
{
	
	int year;
	int month;
	int day;
	string desc;
	string checker;

public:
	Appointment();
	Appointment(string s);
	friend istream& operator >> (istream& ins, Appointment& arg);
	friend ostream& operator << (ostream& out, const Appointment& arg);
	bool compare(const Appointment& arg1, const Appointment& arg2);
	int getYear() const { return year; };
	int getMonth() const { return month; };
	int getDay() const { return day; };
	string getDesc() const { return desc; };
	string getChecker() const { return checker; };
};

#endif
Feb 17, 2020 at 8:21am
Why is
#include "Appointment.h"
in Unsorted.h?

Dump this, it's doing nothing useful: typedef Appointment ItemType;


Change this
ItemType* getitem_arr() const { return item_arr; };
to
Appointment * getitem_arr() const { return item_arr; };


Your base class appears to directly refer to an inherited class. This is a design error. Base classes should not know or care about anything derived from them.
Last edited on Feb 17, 2020 at 10:31am
Feb 17, 2020 at 3:01pm
The assignment description wants the appointment class to be aliased as ItemType. Also the reason I have the base class "knowing" about the child class is its needs to use ItemType objects to fill its array.

If I don't have Appointment.h in Unsorted.h, then I can't use ItemType in the unsorted files.
I tried fixing this by using a forward declaration and commenting out #include Appointment.h" so my unsorted.h file now looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef LAB3_H
#define LAB3_H 
#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
//#include "Appointment.h"
#include <vector>


using namespace std;

class Appointment; // forward declaration

class UnsortedType
{
    protected:
		int length = 0;
		int size;
	    //string *item_arr; //dynamic array of items
		ItemType *item_arr;
		//ItemType temp_obj;

	
    public:
		UnsortedType();
		UnsortedType(int num);
		UnsortedType(const UnsortedType& arg); // copy constructor
		UnsortedType& operator = (const UnsortedType& arg); // assignment operator
		~UnsortedType(); //destructor
		bool isFull();
		void PutItem(string s);
		int getLength() const { return length; };
	    ItemType* getitem_arr() const { return item_arr; };

};



#endif 
Last edited on Feb 17, 2020 at 3:07pm
Topic archived. No new replies allowed.