Thread: Strongly typed collections

  1. #1
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438

    Strongly typed collections

    I'm attempting to create a strongly typed collection of Vehicle objects in C++. I've been pondering why this won't compile for awhile and I can't figure it out. Anybody?

    Code:
    #ifndef VEHICLECOLLECTION_H
    #define VEHICLECOLLECTION_H
    
    #include <list>
    
    class VehicleCollection
    {
    public:
    	VehicleCollection();
    	~VehicleCollection(void);
    private:
    	list<Vehicle> lst;
    };
    
    #endif
    Error:
    error C2143: syntax error : missing ';' before '<'

  2. #2
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    Two problems. First, you must use std::list instead of just list. Second, there is no declaration or definition of the Vehicle type, and no include of a header in which Vehicle is declared.

  3. #3
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    Awesome, thank you! I was getting a weird error when I had a destructor for Vehicle. Once I removed it, everything compiled ok.

    Code:
    #ifndef VEHICLECOLLECTION_H
    #define VEHICLECOLLECTION_H
    
    #include <list>
    #include "Vehicle.h"
    
    class VehicleCollection
    {
    public:
    	VehicleCollection();
    	~VehicleCollection(void);
    private:
    	std::list<Vehicle> lst;
    };
    
    #endif

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Poll - Terrorism & Torture
    By Kybo_Ren in forum A Brief History of Cprogramming.com
    Replies: 38
    Last Post: 12-04-2006, 02:08 PM
  2. Messing with listbox collections and random fun
    By DanFraser in forum C# Programming
    Replies: 0
    Last Post: 06-20-2005, 07:40 PM
  3. Icon collections
    By _Elixia_ in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 07-12-2003, 04:41 PM
  4. just one more thing..
    By xlord in forum C Programming
    Replies: 2
    Last Post: 10-16-2002, 09:13 PM
  5. Collections
    By Klaas in forum C++ Programming
    Replies: 1
    Last Post: 04-05-2002, 03:53 PM