Hello,
I am trying to create a new type. I want to use new to allocate 4 spaces to hold 4 new records but get an error when I try to do this. Can someone correct my errors?
Type Employee
Dim as string fname, lname
End Type
Dim p as Employee Ptr = New Employee[5]
p[0] = "Hillsdale Beattle"
print p->fname
The error I get is 'Invalid assignment/conversion"
How do I allocate enough space using the array format of new to store my two variables?
Also is there a way to use new to form a new constructor or to point to a constructor? Can you give me an example?
Thanks
Using New to create a new type
Using New to create a new type
Last edited by saraaku on Aug 10, 2007 19:07, edited 1 time in total.
No its not the right forum.
The following code works, but I am not sure where you were going with what you were doing, so you are going to have to be more specific if this is not what you wanted.
The following code works, but I am not sure where you were going with what you were doing, so you are going to have to be more specific if this is not what you wanted.
Code: Select all
Type Employee
Dim as string fname, lname
declare constructor(fname as string, lname as string)
End Type
constructor Employee(fname as string, lname as string)
this.fname=fname
this.lname=lname
end constructor
Dim p(5) as Employee Ptr
p(0)=new Employee("Akua","Asamoah")
print p(0)->fname
saraaku, you are using the array form of NEW correctly. Like others have said, the problem is you're trying to assign a string value to an Employee object.
It is an invalid assignment/conversion because Employee has neither a constructor nor assignment operator overloaded to take a string as a parameter. It needs to have either one to allow p[0] = "string".
It is an invalid assignment/conversion because Employee has neither a constructor nor assignment operator overloaded to take a string as a parameter. It needs to have either one to allow p[0] = "string".
-
- Posts: 5494
- Joined: Sep 12, 2005 20:06
- Location: California