• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 958
  • Last Modified:

Vector ADT

I'm trying to use the vector class in C++ standard library, here is a snapshot of my code

#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <conio.h>
#include <iostream.h>
#include <dos.h>
#include <vector.h>

#define FALSE 0
#define TRUE !FALSE   //warning here
#define MAXCOL 80

Class MyClass
{
public:
        MyClass();
       //some functions
private:
       //some variables
       vector<int> Scores(50);   // Errors at this line
};

I recieve the following errors:
Type name expected
Declaration missing ;

and the following warning
Redefinition of TRUE is not identical
I don't what this line had to do with the vector, without the vector include & decalartions lines, i have no errors or warnings.
0
JessyEzzy
Asked:
JessyEzzy
  • 9
  • 7
1 Solution
 
AxterCommented:
Hi JessyEzzy,
> >Class MyClass

The keyword class should be lower case
class MyClass
{

David Maisonave :-)
Cheers!
0
 
AxterCommented:
Also all the files in teh STL library do not have *.h extensions.
Both <vector.h> and <iostream.h> are not part of the C++ standard, and should not be used.
These files are not portable.

You should use the extensionless version which is part of the standard.
#include <iostream>
#include <vector>
0
 
JessyEzzyAuthor Commented:
The keyword class mistake is made by me only while I was writing the code here,
as for the includes I removed the 'h' as you said I got the same errors plus new one saying:
"Cannot create pre-compiled header: code in header" in Vector.h(984,2)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
AxterCommented:
>>"Cannot create pre-compiled header: code in header" in Vector.h(984,2)
Try doing a recompile-All

What compiler are you using?

If you're using a very old compiler like Turbo C++, then you'll have to stick with vector.h

When you use <vector> you also want to add using namespace std;

#include <iostream>
#include <vector>
using namespace std;
0
 
JessyEzzyAuthor Commented:
I'm using Borland C++ 5.0
I included the line using namespace std; I got 4 errors and a warning, the warning is
Cannot create pre-compiled header: code in header" in Vector.h(984,2)

3 errors  "Illegal structure operation" at utility.h(84,38),utility.h(84,40),utility.h(84,8)

and an error at the line vector<int> Scores(50);  ") expected"

I compiled all as u said.
0
 
AxterCommented:
Can you copy and paste the code here.

I think there's something that in the code, that in the code you posted.
0
 
AxterCommented:
Did you do a recompile ALL?
0
 
JessyEzzyAuthor Commented:
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <conio.h>
#include <iostream>
#include <dos.h>


#define FALSE 0
#define TRUE !FALSE
#define MAXCOL 80

#include <vector>
using namespace std;


class ClubMember
{
public:
      ClubMember();
      void setName(const char* fn, const char* ln);
      void setAddress(const char* ad1, const char* ad2);
      void setTelnum(const char* tn);
      void setGradYear(const int gy);
      void setClubMemberData(const char* fn, const char* ln, const char* ad1,
            const char* ad2, const char* tn, const int gy);
      const char* getFirstName() const { return firstname; }
      const char* getLastName() const { return lastname; }
      const char* getAddrOne() const { return addrOne; }
      const char* getAddrTwo() const { return addrTwo; }
      const char* getTelnum() const { return telNum; }
      int getGradYear() const { return gradYear; }
private:
      char firstname[20];
      char lastname[20];
      char addrOne[40];
      char addrTwo[40];
      char telNum[15];
      int gradYear;
                vector<int> scores(50);
};

the rest are the definition of the member functions and the main, there is nothing wrong in them no errors.
0
 
AxterCommented:
Did you do a recompile ALL?
0
 
JessyEzzyAuthor Commented:
I have 3 options Compile, Make All, Build All
I did a Build All
0
 
AxterCommented:
>>                vector<int> scores(50);


I forgot, that you're declaring this in a class.
You can't put constructor arguments in your class declaration.
0
 
JessyEzzyAuthor Commented:
I don't understand :(
where shall i put it then?
0
 
AxterCommented:
I'm not sure what's wrong with your STL library, but for now, try putting it back to the <vector.h> and <iostream.h> and comment out the using namepsace std;

For your scores variable, you need to pass the 50 value in the constructor initialize list.

Something like this:

class foo
{
  foo():scores(50)
  {
    //constructor code here
  }
  vector<int> scores;
};

or

class foo
{
  foo();
  vector<int> scores;
};

  foo::foo():scores(50)
  {
    //constructor code here
  }
0
 
AxterCommented:
FYI:
If you have multiple data members that need data pass to the data member's constructor, you can use the following syntax:

class foo
{
  foo():scores(50), obj1(123), strobj("Hello")
  {
    //constructor code here
  }
  vector<int> scores;
  vector<int> obj1;
  string strobj;
};

Notice that there is a full colon before the data member on the initialize list
0
 
JessyEzzyAuthor Commented:
I got the same 2 old errors
Type name expected
Declaration missing ;

class foo
{
  foo():scores(50) // 3rd error
  {
    //constructor code here
  }
  vector<int> scores;      // 2 errors here
};

3rd: scores is not an unambigious base class of foo

same errors for ur other suggested code
0
 
JessyEzzyAuthor Commented:
Tell u what, I really lost hope and I don't want 2 use vectors no more, so I'll give u the points  for ur great help(not so much sorry, but i'm really in lack of points) and just close the question & forget all about it
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 9
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now