Use a class as parameter for an constructor for another class

I am trying to create a class which has an constructor which uses an instantation of an another class as parameter.

So for instance

1
2
3
4
5
6
7
8
9
10
11
12
Class James{
public:
James(string);
void getJamesID();
};

Class Jorn{
public:
Jorn(James);

};


It doesn't work.. what is my problem?
Do it this way
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Class James
{
public:
	James(string);
	void getJamesID();
};

Class Jorn
{
public:
	Jorn(string test)
	{
		James(test)
	}
};
- Class is written with a capital
- Members have only been declared but no definition.
I don't understand why you doing it with a string.. The reason why I want to create a object with a constructor with another class as parameter, is because i want to use it's member function to edit the first class..
DrJones, if you just change "Class" to "class" I don't see any problems with your code. What is it that doesn't work?
When i do it i get this error "Call to implicit-deleted copy constructor of James"
Ok, so the code you have posted is obviously not your real code. For some reason your James class could not be copied. It could be because it contains a non-copyable member, like std::fstream. If you don't need the object to be copied you could pass it by reference to the constructor.
1
2
3
4
class Jorn{
public:
	Jorn(const James&);
};
Last edited on
Well.. I have a class which loads an image, and using this class I am able to get,set pixel values and so on.

my idea was to create class for the different actions I wanted to perform on this image, so by given it as parameter, it would be easier to manipulate the pixels which is within the image class.

So yes I am using Fstream
Yeah, then it sounds like passing the object as reference is the way to go. My example uses const but if you want to manipulate the object you should leave it out.
Topic archived. No new replies allowed.