473,943 Members | 32,815 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array of Pointers to Objects

I'm fairly new to c++ coming from c, so I'm a little confused.

I have the following:
Page *pageTable;
Desc *descTable;
pageTable = new Page[100]; //array of Page objects
descTable = new Desc[100]; //array of Desc objects

Later on I have the following for loop:

for(i=0;i<100;i ++)
{
if(descTable[i].valid==true)
{
(descTable[i].file)->writePage(page Table[i].pageNo,descTab le[i]);
}
}

The Desc class has a (bool valid) and (int pageNo) and (File* file).
The file method writePage is defined as:
writePage(int pageNo, Page* pagePtr);

When I try to compile this, I get the following error:
error: no matching function for call to `File::writePag e(int&, Page&)'
error: candidates are: const Status File::writePage (int, Page*)

I just can't seem to figure out the correct way to pass around the
pointers. If I need to change something I'd like it to be the code
here, not the member functions of File.

Anyone have any ideas? This has been driving me crazy! Thanks!
Jul 22 '05 #1
9 1578
error: no matching function for call to `File::writePag e(int&, Page&)'
error: candidates are: const Status File::writePage (int, Page*)

The second argument is of type "Page*", a pointer to a "Page" object.

You're not giving it a pointer. Change:

(descTable[i].file)->writePage( pageTable[i].pageNo, descTable[i] );

to:

(descTable[i].file)->writePage( pageTable[i].pageNo, &descTable[i] );
-JKop

Jul 22 '05 #2

"JKop" <NU**@NULL.NULL > wrote in message
news:PF******** ***********@new s.indigo.ie...
error: no matching function for call to `File::writePag e(int&, Page&)'
error: candidates are: const Status File::writePage (int, Page*)

The second argument is of type "Page*", a pointer to a "Page" object.

You're not giving it a pointer. Change:

(descTable[i].file)->writePage( pageTable[i].pageNo, descTable[i] );

to:

(descTable[i].file)->writePage( pageTable[i].pageNo, &descTable[i] );


Or this

descTable[i].file->writePage( pageTable[i].pageNo, descTable + i );

This isn't a C++ issue, you would have had exactly the same error in C.

john
Jul 22 '05 #3
Kareem Nutt wrote:
I'm fairly new to c++ coming from c, so I'm a little confused.

I have the following:
Page *pageTable;
Desc *descTable;
pageTable = new Page[100]; //array of Page objects
descTable = new Desc[100]; //array of Desc objects

Later on I have the following for loop:

for(i=0;i<100;i ++)
{
if(descTable[i].valid==true)
Just a nit-pick on your style: this could be (and would read a bit
clearer):

if (descTable[i].valid)
{
(descTable[i].file)->writePage(page Table[i].pageNo,descTab le[i]); ^^^^^^^^^^^
Are you sure your actual code has this? }
}

The Desc class has a (bool valid) and (int pageNo) and (File* file).
The file method writePage is defined as:
writePage(int pageNo, Page* pagePtr);

When I try to compile this, I get the following error:
error: no matching function for call to `File::writePag e(int&, Page&)'
error: candidates are: const Status File::writePage (int, Page*)

I just can't seem to figure out the correct way to pass around the
pointers. If I need to change something I'd like it to be the code
here, not the member functions of File.

Anyone have any ideas? This has been driving me crazy! Thanks!


'descTable[i]' is of type Desc. Your function needs Page*. It needs
_an_address_ of what it is going to write, and you're providing the
_value_ of some other type. Getting warmer? Can you do it yourself
now? If not, here is the corrected statement:

descTable[i].file->writePage(page Table[i].pageNo, &pageTable[i]);

or

descTable[i].file->writePage(page Table[i].pageNo, pageTable + i);

(as you can see I removed the extraneous parentheses as well).

Victor
Jul 22 '05 #4
John Harrison wrote:
[..]
Or this

descTable[i].file->writePage( pageTable[i].pageNo, descTable + i ); ^^^^^^^^^
pageTable.
This isn't a C++ issue, you would have had exactly the same error in C.


:-)
Jul 22 '05 #5

"Victor Bazarov" <v.********@com Acast.net> wrote in message
news:BU******** *******@newsrea d1.dllstx09.us. to.verio.net...
John Harrison wrote:
[..]
Or this

descTable[i].file->writePage( pageTable[i].pageNo, descTable + i );

^^^^^^^^^
pageTable.

This isn't a C++ issue, you would have had exactly the same error in C.


:-)


I must be being dense. I don't see it.

john
Jul 22 '05 #6
John Harrison wrote:
"Victor Bazarov" <v.********@com Acast.net> wrote in message
news:BU******** *******@newsrea d1.dllstx09.us. to.verio.net...
John Harrison wrote:
[..]
Or this

descTable[i].file->writePage( pageTable[i].pageNo, descTable + i );


^^^^^^^^^
pageTable.
This isn't a C++ issue, you would have had exactly the same error in C.


:-)

I must be being dense. I don't see it.


You don't see what? In the original post the second argument is said
to be of type Page*, not Desc*. Reread it:
> error: candidates are: const Status File::writePage (int, Page*)


V
Jul 22 '05 #7

"Kareem Nutt" <me********@gma il.com> wrote in message
news:V-*************** *****@comcast.c om...
I'm fairly new to c++ coming from c, so I'm a little confused.

I have the following:
Page *pageTable;
Desc *descTable;
pageTable = new Page[100]; //array of Page objects
descTable = new Desc[100]; //array of Desc objects

Later on I have the following for loop:

for(i=0;i<100;i ++)
{
if(descTable[i].valid==true)
{
(descTable[i].file)->writePage(page Table[i].pageNo,descTab le[i]);
}
}

The Desc class has a (bool valid) and (int pageNo) and (File* file).
The file method writePage is defined as:
writePage(int pageNo, Page* pagePtr);

When I try to compile this, I get the following error:
error: no matching function for call to `File::writePag e(int&, Page&)'
error: candidates are: const Status File::writePage (int, Page*)

I just can't seem to figure out the correct way to pass around the
pointers. If I need to change something I'd like it to be the code
here, not the member functions of File.


You're passing a Desc (object) where a Page* (pointer) is expected. Others
have suggested you pass &descTable[i], but that's a pointer to a Desc
object, not a pointer to a Page object. I'm not sure which Page object you
want, though. Is it the one at the same location [i] as the Desc object, or
the one whose index is the same as the pageNo value of the Desc object? Or,
is it the job of the writePage function to index into the pageTable array,
using that index, to get the correct Page object?

Without seeing the (relevant) contents of writePage, I can't tell what you
really want. If writePage uses the pageNo to index into an array that
you're passing it, then what you want is to pass pageTable, not
descTable[i]. If what writePage expects is a pointer to a single Page
object, then you want to pass it &pageTable[something], but again, what
"something" is depends upon whether you're trying to write out the page at
index [i] or the page whose index is the pageNo value from the Desc object.
If the former, then you want to use [i]. If the latter, then you want to
use [pageNo].

There is another inconsistency in your code. You pass pageTable[i].pageNo
as the page number int parameter, but you've stated that pageNo is a member
of the Desc object! Given that, shouldn't the first parameter be
descTable[i].pageNo?

If you have the source for writePage, then you might want to post its code
here, along with the two structures. That might help sort this out. (If
writePage belongs to some library, then read the documentation on what the
parameters should be.)

-Howard

-Howard


Jul 22 '05 #8

"Victor Bazarov" <v.********@com Acast.net> wrote in message
news:k6******** *******@newsrea d1.dllstx09.us. to.verio.net...
John Harrison wrote:
"Victor Bazarov" <v.********@com Acast.net> wrote in message
news:BU******** *******@newsrea d1.dllstx09.us. to.verio.net...
John Harrison wrote:

[..]
Or this

descTable[i].file->writePage( pageTable[i].pageNo, descTable + i );

^^^^^^^^^
pageTable.

This isn't a C++ issue, you would have had exactly the same error in C.

:-)

I must be being dense. I don't see it.


You don't see what? In the original post the second argument is said
to be of type Page*, not Desc*. Reread it:
>>>>> error: candidates are: const Status File::writePage (int, Page*)


Right, I'm being dense.

john
Jul 22 '05 #9
Howard wrote:
[..]
If you have the source for writePage, then you might want to post its code
here, along with the two structures. That might help sort this out. (If
writePage belongs to some library, then read the documentation on what the
parameters should be.)


You're absolutely correct. For whatever reason we assumed that what the
OP wrote was _almost_ there, except he passed by value instead of by
pointer. It could be that he just needed to pass the address of the very
first element of the array and the function will index it itself.

V
Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3348
by: James | last post by:
Hi, I'm hoping someone can help me out. If I declare a class, eg. class CSomeclass { public: var/func etc..... private varfunc etc..
67
4572
by: Ike Naar | last post by:
Hi, Asking your advice on the following subject: Suppose I want to find out whether a given pointer (say, p) of type *T points to an element of a given array (say, a) of type T. A way to achieve this would be a linear search through the array: int ptrInArrSafe(T *p,T *a,int max) /* check whether p points to an element of a */
8
3705
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was static; if the input file contained more than entries, tough. This time I want to do it right - use a dynamic array that increases in size with each word read from the file. A few test programs that make use of **List and realloc( List, blah...
7
2498
by: Frank M. | last post by:
I'm trying to declare an array of pointers to structures so that I can make the last element a NULL pointer. I figure that it would more easily allow my library routines to know when to stop processing the array. typedef struct screen_disp { int sd_row; int sd_col; char *sd_buff; } SCR_DISP;
5
1963
by: Chris | last post by:
Hi, to create an array of 2 objects (e.g. of type '__gc class Airplane') I need to do : Airplane * arrAirplanes __gc = new Airplane* __gc; arrAirplanes = new Airplane("N12344"); arrAirplanes = new Airplane("N12345"); Actually, I create an array of Airplane-pointers first and then create the
23
7456
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these in an array. The application compiles but aborts without giving me any useful information. What I suspect is happening is infinite recursion. Each Directory object creates an array of Subdirectories each of which has an array of...
3
1694
by: Scotty | last post by:
I'm a C++ novice and need help figuring out some odd behavior I've encountered. Here's the situation: I create a class and have its constructor store a random number in a private "number" variable. The class also has a "getNumber()" function that returns its stored number. A function in the program creates five objects of this class and five pointers to these objects, the latter of which are stored in a global array. When "getNumber()"...
17
7275
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need to show the array data to the end user. Can I do that? How?
2
2995
by: StevenChiasson | last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller. This is more or less, your standard dynamic address book program. Adding, and listing work just fine. However, deleting, editing and viewing relies on member function retAddress. This function returns an array of pointers that are pointing to created objects. In action, all it...
5
3666
by: Immortal Nephi | last post by:
I would like to design an object using class. How can this class contain 10 member functions. Put 10 member functions into member function pointer array. One member function uses switch to call 10 member functions. Can switch be replaced to member function pointer array? Please provide me an example of source code to show smart pointer inside class. Thanks....
0
10142
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11133
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11302
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8228
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4515
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3516
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.