Helpful Information
 
 
Category: C Programming
Class prototype?

Such a thing as a class prototype? Im sure there is... I need to know how to use it since I have a class that needs to derive an object from another class and use it but the other class is defined after it and if i define it before it I will hit the same problem with its class.

Just declare it first:

class parent;

class child : public parent
{
...
};

class parent
{
...
};

if I declare it first then I have the same problem. The 2 classes are inter dependent. they both use oneanother.

Post some code. I don't understand what your problem is.

I don't really think you can do what you are trying to do. You need to create a parent class that contains the methods/properties that are needed in either both or one of the classes. Then you can create the other two classes that inheret from the parent and not each other.

As far as prototypes, a class has one just like a function. The class prototype should be in it's own header file and the implementation (or actual coding) for the class should be in a related cpp file.

Hello,

do you mean you are trying to do something like:

class class1
{
public:
.....
private:
class2 newClass;
};

class class2
{
public:
.....
private:
class1 newClass;
};


If this is what you are trying to do, you cannot do this because it would just not work. Imagine, if you declare an object of class1, class one would declare an object of class2, which would declare an object of class 1, etc... to infinity.

Carl

Can't you make the derived class a friend class then it can use parent properties


Mark

Don't friend classes just access protected methods / properties?

cARl

Yes you are right but i thought that's what the guy was asking
A way to access protected members of the parent class


He didn't make it too clear when he posted, and im not entirely sure that making the class a freind class could do this anyway


Im still a bit fuzzy about the class stuff in C++ so im just assuming


Mark

I have the exact same problem, and I understand whats going on. I tried making a header file with like:

classname::funct(int x, int y);
classname2::funct(int foo, int bar);

But it does not work....
3 mins later.
Ok I think I figured it out. put all your class definitions together (in one header file if you want) then but their functions afterwards. I made 4 header files:
Proto.h, Ply.h, Eny.h and Ctrl.h
as long as you put da declarations together before the functions using dem, it should work
*My first Post*
wow, could i be any more noobish? 2002... I did not thing to look at the date sorry fourm community










privacy (GDPR)