Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vector Class : wont take struct as typename

Status
Not open for further replies.

Karl Blessing

Programmer
Feb 25, 2000
2,936
US
I have some code given to me by a friend, and I'm just going thru it and cleaning it up and such, the declarations go by just fine, but there is this one line of code that says

Type name expected

I am using Borland C++ 5.02 since that allows the namespace type of declaration (no .h)

the line that has that error is

Code:
vector<resident_record> RESIDENT_DB;

this is the structure of that &quot;resident_record&quot;

Code:
struct resident_record
{
	string first_name;
	string last_name;
	string ss_no;
	int apt_no; 
	string birthday; 
	string phyiscian; 
	string closest_relative_first_name;
	string closest_relative_last_name;
	int rent;
	int months_behind;
	string move_in_date;
	string medical_insurance_company;
};


Any clues?
I dont know much about vectors, or vector classes, but looking up the syntax it seems right, I just havent found any examples using a structure as the type name.

Thanks Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
Hm, this compiles file in MVC++ 6.0 Pro. I would try defining the vector like this:

vector<struct resident_record> RESIDENT_DB;

This is how you would normally declare a struct that did not include a name after its tag. What I mean is if the struct was defined like this:

struct resident_record_tag
{
string first_name;
string last_name;
...
} resident_record;

Then your definition would make sense. However, MVC++ most be smart enough to avoid compilation problems in this secenario. I've never used Borland so I'm not entirely sure. Try the other definition, and also make sure the file your defining the vector in knows about the struct definition.

bitwise
 
it still gives the same error, even with the modifications you sugested. Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
I don't know. This is a debugging problem, and I'm not familer with the Borland compiler. Are you including the vector class like this?:

#include <vector>
using namespace std;

bitwise
 
the first line was there, the second line helped, I went through fixing a bunch of errors (This guy had everything from misspelled varibles, to no initialization/declaratoin, to case sentative related errors, etc, it's a wonder how he has 3 years of C++ under his belt)

I am down to 2 errors.

(opposed to 26 that I fixed)

a operator error, identifier error.


aptcomplex.cpp(72,3): Identifier 'print_records' cannot have type qualifier

Code:
.....
DataBase::DataBase() /* reads datafile and stores*/
{
    resident_record r; //database record
    ifstream input; //input iterator
    string f;
    void DataBase::print_records()  <---- ERROR
    {
.....


aptcomplex.cpp(313,21): Lvalue required

Code:
RESIDENT_DB.size()--;

so thats what I'm down to. Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
welp I am down to only one error, and thats that LValue.

I fixed about 20 more errors when I found out he had one heck of alot of typos, stuff like for many ) he had 0, or too many closing braces, etc. Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
The decrement operator (--) can not be used on a function call. The 'Lvalue required' error means that you need a left-hand side of your function call. The size member I assume returns the size of RESIDENT_DB, whatever that may be. Well, that will not decrese the size by one. That is an accessor function. To fix that do this:

1. int size = RESIDENT_DB.size() - 1;

However, whoever wrote that code looks like they want to decrease the size of the &quot;size&quot; data member of the RESIDENT_DB class/struct. To do that you would need another function:

RESIDENT_DB.setsize(RESIDENT_DB.size() - 1);

Or if size is a public member which might be the case then your new line could look quite similar to the original:

RESIDENT_DB.size--;

Anyway, it's not very hard it just all depends on what needs to be accomplished.

bitwise
 
kb244, is better you to put this question in borland c++ discution list. John Fill
1c.bmp


ivfmd@mail.md
 
bitwise, I found that out, I was just debugging the guy's code , which was a *.cpp, and well I went to a C++ chat channel, discussed the code (you see i dont know vectors myself that much, and the fact it was -- on a function made me wonder)

turns out whoever wrote this really had no clue what they were doing ( I fixed nearly 60 bugs, mostly related to typos, and mispellings )

in any case, I will have to rewrite that function, since the function call appears to be searching for the current selected item in a vector class, then it tries to delete it. I was intending to stick this in VC++ or some other compiler anyways (The guy wrote it for Unix, but thus far, other than that redundant method of removing, it seems to be multi-platform capable)

But thanks for your help (I may just rewrite my own version , based on the concept he was trying to code, I may try something more industry standard, such as Access, SQL , oracle, etc) Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
I tried the same code and it works fine.I am giving the code which i used
#include <iostream>
# include<vector>
# include<string>
using namespace std;

struct resident_record
{
string first_name;
string last_name;
string ss_no;
int apt_no;
string birthday;
string phyiscian;
string closest_relative_first_name;
string closest_relative_last_name;
int rent;
int months_behind;
string move_in_date;
string medical_insurance_company;
};
int main(int argc, char *argv[])
{
vector<resident_record> record;

}
Welcome to the Pythian Games!
Long live Godess Athena!
dArktEmplAr of Delphi Oracle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top