Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include"stdafx.h"
#include<iostream>
#include<ctime>
#include<cstddef>
#include<fstream>

using namespace std;

class person
{
	char *name;
public:
	person(){};
	void set_name(char *nam)
	{
		name=nam;
	}
	char* get_name()
	{
		return name;
	}
};
class student:public person
{
	 int year_of_joining;
	 int rollno;
	 char *stream;
public:
	student(int year,int roll,char *str,char *nam);
	student *next,*prev;
};
student::student(int year,int roll,char *str,char *nam)
{
	year_of_joining=year;
	rollno=roll;
	stream=str;
	this->set_name(nam);  //call to the person class to define name
	next=NULL;
	prev=NULL;
}
class linklist
{
	files *f;
	student *start,*temp;  //pointer to the first and the last member of the linklist respectively
public:
	linklist(int year,int roll,char *str,char *nam);
	void append(int year,int roll,char *str,char *nam);
	char* show_name();
};
char* linklist::show_name()
{
	return temp->get_name();
}
linklist::linklist(int year,int roll,char *str,char *nam)
{
	student *ptr=new student(year,roll,str,nam);
	start=ptr;
	temp=ptr;
}
void linklist::append(int year,int roll,char *str,char *nam)
{
	student *ptr1=new student(year,roll,str,nam);
	temp->next=ptr1;
	ptr1->prev=temp;
	temp=ptr1;
}
class files
{
	ifstream *in;
	ofstream *out;
public:
	files();
};

int main()
{
	linklist l(2009,1809317,"cse","bhawin");
	l.append(2009,1809315,"cse","anshul");
	return 0;
}



in the above code there is a problem at first private member of class linklist
the error says:missing type specifier - int assumed. Note: C++ does not support default-int
and the second error is - syntax error : missing ';' before '*'

i just can't understand why i cant add class object file class as a private member of linklist class
Posted

To fix your problem you may add a forward declaration to the files class, namely:

C#
class files; // forward declaration of the class 'files'
class linklist
{
  files *f;
  // ..
 
Share this answer
 
Comments
bhawin parkeria 13-Aug-13 7:13am    
thnx a lot
CPallini 13-Aug-13 8:12am    
You are welcome.
You have a forward reference which is not allowed. The files class needs to be defined before the linklist class.
 
Share this answer
 
Comments
CPallini 13-Aug-13 8:12am    
My 5.
Richard MacCutchan 13-Aug-13 11:08am    
:thumbsup:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900