why.. error using list container...

This is a discussion on why.. error using list container... within the C++ Programming forums, part of the General Programming Boards category; I dont know.. why MVC++ teasing me..... trying to use list container.. but giving me the error... see code of ...

  1. #1
    Registered User jawwadalam's Avatar
    Join Date
    May 2002
    Posts
    131

    why.. error using list container...

    I dont know.. why MVC++ teasing me.....

    trying to use list container.. but giving me the error...

    see code of main.cpp I have mentioned errors...
    and also code of student class is next to main.cpp
    project in self extractor form is attached..
    ----------main.cpp-------------
    Code:
    #include <iostream.h>
    #include <conio.h>
    #include <list.h>
    #include "Menu.h" // for the Menu function...
    //list<student> stlist;//giving me error here...??? 
    //If I uncommented .. the error is "error C2143: syntax error : missing ';' before '<'" 
    //#include "student.h"
    #include "student.cpp"
    
    int main(void)
    {
    	
    	Menu(); //to call menu function defined in Menu.h 	
    	list<student> stlist;//giving me error here...tooo??? 
    	return 0; //error is "undeclared identifier."
    }
    code of student.cpp
    Code:
    // student.cpp: implementation of the student class.
    //
    //////////////////////////////////////////////////////////////////////
    
    #include "student.h"
    #include <iostream.h>
    #include <string.h>
    
    
    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////
    
    student::student() : rono(0), phno(0)
    {
    	setname("Undefined name.");
    	setaddress ( "Undefined Address." );
    	//default constructor...
    }
    
    student::~student()
    {
    	
    }
    
    /******************************************************************
    	
    	  Defination / Implementation of student class member functions.					
    
    /*****************************************************************/
    
    
    
    void student::setrono(long int rn)
    {
    	rono = rn;
    }
    
    long int student::getrono(void)
    {
    	return rono;
    }
    
    void student::setphno(long int pn)
    {
    	rono = pn;
    }
    
    long int student::getphno(void)
    {
    	return phno;
    }
    
    void student::setname(char *na)
    {
    	strcpy( name,na);
    }
    
    char* student::getname(void)
    {
    	return name;
    }
    
    void student::setaddress(char* ad)
    {
    	strcpy ( address, ad);
    }
    
    char* student::getaddress(void)
    {
    	return address;
    }


    code of student.h

    Code:
    /*****************Purpose of the Class...**************************/
    /*  Class student's object handles the roll no(long int rono), 
    /*  phone no (long int phno), name (char* name) and 
    /*	address (char* address) of a student..
    /*****************************************************************/
    
    ////////////////////////Interface of the Class....///////////////
    
    class student  
    {
    private:
    	long int rono, phno;
    	char *name, *address;
    public:	
    	
    	
        student();  //constructor....heehehehheh I know it.. :D
    	virtual ~student(); //Destructor.....but virtual
    	
    	/*//////////////////to set and get "Roll no".///////*/
    	long int getrono(void);
    	void setrono(long int);
    	///////////////////////////////////////////////////
    
    	////////////////////to set and get "Phone no"///////
    	long int getphno(void);
    	void setphno(long int);
    	///////////////////////////////////////////////////
    	
    	///////////////////to set and get "Name".//////////
    	char* getname(void);
    	void setname(char* );	
    	///////////////////////////////////////////////////
    
    	////////////////////to set and get "Address"///////
    	char* getaddress(void);
    	void setaddress(char* );
    	//////////////////////////////////////////////////*/
    
    };
    One day you will ask what more important to you..
    I will say my life..
    and You will leave me with even knowing
    that
    You are my Life (L)

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    272
    The standard header is <list>, not <list.h>. In the std namespace.
    Joe

  3. #3
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Code:
    //list<student> stlist;//giving me error here...??? 
    //If I uncommented .. the error is "error C2143: syntax error : missing ';' before '<'" 
    //#include "student.h"
    #include "student.cpp"
    Look, you're declaring a list of type student before student is even defined (included). Move the declaration below the #includes for your student class. Also, you shouldn't be including that cpp file in your project, you don't include cpp's, you compile and link them.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  2. How do you search a list container....
    By chadsxe in forum C++ Programming
    Replies: 22
    Last Post: 07-16-2005, 01:39 PM
  3. Linked List
    By jpipitone in forum C Programming
    Replies: 4
    Last Post: 03-30-2003, 09:27 PM
  4. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 05:20 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21