LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-15-2012, 06:41 PM   #1
ofer4
Member
 
Registered: Apr 2012
Posts: 100

Rep: Reputation: Disabled
struct and class problem


hi

i created a header file:

Code:
#ifndef _DeliveryVehicleList
#define _DeliveryVehicleList


typedef struct _List* Plist;
typedef struct _List List;


struct _List 
{
	Plist next;
	Plist prev;
	DeliveryVehicle* deliveryvehicle;
};

class vehicle_list
{
protected:
	Plist first_list;
public:
	vehicle_list();
	bool add_list(Plist plist);
	Plist get_first_list();
	Plist create_list(DeliveryVehicle* deliveryvehicle);
	~vehicle_list()

};


#endif // !_DeliveryVehicleList
and this is the cpp file:

Code:
#include <iostream>
#include "DeliveryVehicleList.H"
#include "Parcel.H"
#include "DeliveryVehicle.H"
#include "FastDeliveryVehicle.H"
#include "ProfessionalDeliveryVehicle.H"

using namespace std;



vehicle_list::vehicle_list()
{
	first_list=(Plist) new(List);
	first_list->next=NULL;
	first_list->prev=NULL;
	first_list->deliveryvehicle=NULL;
}

vehicle_list::~vehicle_list()
{
	delete first_list;
}

bool vehicle_list::add_list(Plist plist)
{
	Plist temp;
	plist->prev=NULL;
	plist->next=first_list;
	first_list->prev=plist;
	return EXIT_SUCCESS;
}

Plist vehicle_list::create_list(DeliveryVehicle* deliveryvehicle)
{
	Plist plist= (Plist)new(sizeof(List));
}
however visual studio show me an error message:

http://img13.imageshack.us/img13/1825/17971379.jpg

please someone can help me to resolve this issue?

i dont knwo what am i doing wrong...

thanks alot
 
Old 06-16-2012, 01:25 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
It looks like you're trying to use new how one would use malloc(), I think. You don't use new that way; you simply give your class constructor with any arguments. Since I guess you just want to use _List's default constructor (I believe structs in C++ are really classes, but with public members), you just give the class name:

Code:
Plist plist = new List;
I've not really looked at the rest of the code, so won't comment on it.

Also "alot" is really two words (see link in my sig).
 
Old 06-25-2012, 04:17 PM   #3
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
I cannot see any constructor with size_t/int as parameter. Why won't you just write:
Code:
Plist plist= new List;
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] C++ class inside struct wagaboy Programming 3 04-09-2011 07:39 AM
Problem to understand Class and comunication between Class. webquinty Programming 5 02-26-2009 10:53 AM
GCC compile problem:struct A have a member variable which is just a struct type name? leon.zcom Programming 3 04-18-2008 04:40 PM
struct in class AquamaN Programming 3 06-29-2004 03:25 PM
g++ and wrong struct member addresses / struct size misreporting sonajiso Linux - General 5 05-22-2004 10:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration