Passing pointers to functions

I have a class constructor that I want to take pointers as formal parameters, but something seems to be going very wrong when I try to call it.

I don't think the details of the constructor are necessary, but I have 3 classes that I have created, called expData, restaurant and table. The expData and restaurant classes have default constructors, while table has the following prototype:

table(expData* firstCustomerPtr, restaurant* rp);

i.e. takes a pointer to an object of expData and a pointer to an object of restaurant.

As an example, say I use the following code:

1
2
3
expData* blah1 = new expData;
restaurant* blah2 = new restaurant;
table blah = table(blah1, blah2);


Which gives me an error: no function for call to 'table::table(expData*&, restaurant*&)'. But my understanding of that code is that I'm passing an expData* and a restaurant* to the function.

I think I'm doing something very wrong here since I am a terrible programmer, but if someone could shed some light, that'd be great!
closed account (Lv0f92yv)
Honestly, I can't see what's wrong with the above code.... Maybe I'm missing something. This works for me:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
using namespace std;

class CDummy {
public:

	CDummy(){};
};

class CAddition {
public:

	CAddition(){};
};

class Test {
public:

	Test( CDummy* d, CAddition* a )
	{
		cout << "made me";
	}
};

int main () {
  CDummy* cdum = new CDummy();
  CAddition* cad = new CAddition();

  Test t = Test( cdum, cad );

  getchar();

  return 0;
}


(Code taken from old tutorial on this site and revised for example).

Maybe it has to do with how you implemented and defined the constructor for table.
Last edited on
That works for me, too, so something seems weird... to be more clear, here's my whole table class, where I've modified the constructor to just be a cout, like the example. I still get the same error

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef table_H
#define table_H

#include <vector>
#include <iostream>
#include "expData.h"
#include "dish.h"
#include "restaurant.h"

class table {
	
public:
	table(expData* firstCustomerPtr, restaurant* rp) {cout << "things" }; //constructor
	~table(void); //destructor 
	dish* getDish(void) {return dishPtr;};
	std::vector<expData*> getOccupants(void) {return occupantsPtr;};
	void removeCustomer(void) {occupants.erase(occupants.begin());};
	void addCustomer(expData* newCustomerPtr);
	int numberSitting {return occupantsPtr.size();};
	restaurant* getRestPtr(void) {return restPtr;};
	
private:
	dish* dishPtr;
	restaurant* restPtr;
	std::vector<expData*> occupantsPtr;
};

#endif 


I've also made it so that the restaurant and expData classes JUST have default constructors... and it still seems to not work.

Another weird thing is if I call, say,
blah = table(&blah1, &blah2)
it gives me an error that it can't find a function table::table(expData**, restaurant**), so that makes me think it realizes that those things are pointers...

Maybe I should just restart from scratch and see what happens.
closed account (Lv0f92yv)
I'm still not sure. My understanding isn't too fluent with preprocessor directives, so I don't know whether or not that is a problem (table not being defined somewhere or something), and I don't know whether or not the fact that you've 'include'ed the expData and dish classes, as well as the restaurant classes have anything to do with it.

Anyone else know what might be the problem? I'm unable to find a solution here.
Topic archived. No new replies allowed.