Discussion Locked

Constructors in C

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Is there a way to make a constructor for user defined types using C?
What I want to do is to detect an instantiation of a user defined datatype in a program file, from a header file, where I defined the datatype.
Am I reinventing the wheel?
Thanks.

4 replies

by bojidar alexandrov

You must implement the user-defined type as class.
The term instantiation has not meaning for data types - it is only for classes.

by bojidar alexandrov

But because the C is not a normal, robust... language in C classes are defined with keywords class, struct, union. That is - struct is actualy a class and you can put in a constructor, but I recommend that you make it a class with constructor for better readibility.

This discussion is closed to new replies.