473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Compillation error (pointers? 0_o)

5
Hello everyone. Working at program i was confused... Please help!



Expand|Select|Wrap|Line Numbers
  1. vector< vector< pair<AnsiString,AnsiString> > > table(100);
  2. //================================================ 
  3. int freeNumber(int a, AnsiString key, vector< vector< pair<AnsiString,AnsiString> > > *table) {
  4. int i=0; 
  5. if ( table[a].empty() ) return 0; //here it'll be broken during debugging
  6.  
  7. for ( ; i<= table[a].size(); i++ ) 
  8.     {
  9.     if ( table[a][i].first == key) return i;     
  10. /* !!!!!!!when trying to compile, writes "[C++ Error]Unit1.cpp(53):E2316 'first' is not a member of 'vector<pair<AnsiString,AnsiString>,allocator<pair<AnsiString,AnsiString> > >' " */ 
  11.     } 
  12.  
  13. return ++i; 
  14. }
  15. //================================================ 
  16. bool Add(int Hvar,vector< vector< pair<AnsiString,AnsiString> > > *table){
  17. string temp1; 
  18. string temp2; 
  19. cin >> temp1; 
  20. cin >> temp2; 
  21. AnsiString key=temp1.c_str(); 
  22. AnsiString data=temp2.c_str(); 
  23. int a=5;
  24.  
  25. table[a][freeNumber(a,key,&table)].first=key; table[a][freeNumber(a,key,&table)].second=data; 
  26. if (table[a][freeNumber(a,key,&table)].first==key) 
  27.  if (table[a][freeNumber(a,key,&table)].second==data) return 1;
  28. return 0; 
  29. }
  30.  //================================================ 
  31. int main(){ 
  32. if (Add(95,&table))  return 0; 
  33. }
  34.  
Jan 23 '08 #1
7 1921
Savage
1,764 Expert 1GB
Are u trying to get first element in vector?
If so use front member function instead.
Jan 23 '08 #2
sierra
5
i'm trying to access the first element of pair<AnsiString,AnsiString>

Any pair is an element of a table constructed as vector of vectors
Jan 23 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
To get you started, a vector of vectors can be treated as a 2D array.

Therefore, you do not pass a pointer to this vector to your function. That would be the address of a 2D array.

You need to pass a reference to the vector instead.

This gets you past the first error. Post again of you cannot clear up the others.
Jan 23 '08 #4
sierra
5
Mmm.. I know about it.. But i really need to use this structure.
So, i think, the problem is in passing. But can smbdy tell me HOW to correctly send "table" to the function..
Jan 23 '08 #5
weaknessforcats
9,208 Expert Mod 8TB
Use a reference:
Expand|Select|Wrap|Line Numbers
  1. int freeNumber(int a, AnsiString key, vector< vector< pair<AnsiString,AnsiString> > > &table) {                         <<<<<<<<<<<<<<
  2. int i=0; 
  3. if ( table[a].empty() ) return 0; //here it'll be broken during debugging
  4. etc...
  5.  
Jan 24 '08 #6
sierra
5
Use a reference:
Expand|Select|Wrap|Line Numbers
  1. int freeNumber(int a, AnsiString key, vector< vector< pair<AnsiString,AnsiString> > > &table) {                         <<<<<<<<<<<<<<
  2. int i=0; 
  3. if ( table[a].empty() ) return 0; //here it'll be broken during debugging
  4. etc...
  5.  
Thx for answering. I tried it. Now all compiles but the string...

25. table[a][freeNumber(a,key,table)].first=key;

freeNumber returns a value(0) but operation '=' don't work. It writes
"Project Project2.exe raised exceptiom class EAccessViolation with mesage 'Access violaton at address 4000684. Write of address 00000000'..."
May be problem is in AnsiString syntax?
Jan 25 '08 #7
weaknessforcats
9,208 Expert Mod 8TB
table[a][freeNumber(a,key,table)].first=key;
Remember, that vector is an array. If [a][freeNumber(a,key,table)] produces a value that is outside the array bounds, you will crash.

If this is, say, [4][5], be sure you have at least 21 elements in your vector.

If you are intending to fill things on a randome basis using a key/value, then consider using a map rather than a vector. A map is an accociative container that has pair members.
Jan 25 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: muser | last post by:
I'm writing a function that isn't showing as an error during compilation, but it is at run time. The exception it is throwing informs me that it is due to my two pointers in that function. It is...
3
by: Filipe Valepereiro | last post by:
I all. I need to write a function that convert one string into a vector. This string represent a serialized form of the vector. So i come up with this piece of code, that compile just fine....
0
by: Jean Stax | last post by:
Hi! I have a MyKey.snk file, which I genereated in command line. I put this file in the workspace / source files directory. My C# code reference it as AssemblyKeyFileAttribute("MyKey.snk"). The...
5
by: Kurt Van Campenhout | last post by:
Hi, I am trying to get/set Terminal server information in the active directory on a windows 2000 domain. Since the ADSI calls for TS don't work until W2K3, I need to do it myself. I'm fairly...
13
by: a.zeevi | last post by:
free() multiple allocation error in C ==================================== Hi! I have written a program in C on PC with Windows 2000 in a Visual C environment. I have an error in freeing...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
10
Roonie
by: Roonie | last post by:
so i signed up this morning and posted an introduction. i mentioned an error that was and then was no longer . . . thus it ceased to be a problem . . . but i guess i spoke too soon. anyways, i...
6
by: Kinbote | last post by:
Hi, I'm trying to make a function that opens a file, reads it in line by line, puts each line into an malloc'd array, and returns the array. I suspect I'm going about it in an atypical fashion, as...
2
by: luis | last post by:
I'm using ctypes to call a fortran dll from python. I have no problems passing integer and double arryas, but I have an error with str arrys. For example: ..... StringVector = c_char_p *...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.