Calling classes from their own constructors

I'm working on a basic game that involves modifying objects. The concept is you find "mods" which you can combine with other "mods" to make a totally new one. I'm wondering if there's a way to set up the constructor for the mod class, so that there is one default constructor, and one constructor that combines 2 objects to create a 3rd. Would this work?

1
2
3
4
5
6
7
class mod
{
	public:
		mod::mod();
		mod::mod(mod a, mod b);

......and so on


I'm unable to compile this right now, but I really want to continue working on the code before I can test it tonight. Thanks in advance.
The code looks fine if you just remove mod:: from line 4 and 5. You might want to pass a and b by reference to avoid unnecessary copying.
Last edited on
Great, thanks. I'll do just that and see how it goes tonight. Appreciate the help.
Did you know you can define member functions (including constructors and destructors) in the class body?
1
2
3
4
5
6
7
8
9
10
#include <iostream>

class Example {
public:

    Example()
    {
        std::cout << "Example()" << std::endl;
    }
};


But if you want to split them up:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// this goes in H file
class Example {
public:

    Example();
};

// this goes in CPP file
#include <iostream>

Example::Example()
{
    std::cout << "Example()" << std::endl;
}

Topic archived. No new replies allowed.