Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using C++ in a C File

0 views
Skip to first unread message

Chris Dyck

unread,
Feb 22, 2001, 3:41:11 PM2/22/01
to
Is there any way to #include a C++ file header into a c file? I'm just
getting compiler errors.

For example:

File is called test.c

\\ file CPP.H

class CcPP
{
};

\\ file test.c

#include "cpp.h"

void main()
{
Ccpp cpp = new CcPP;
}

Thank you,
Chris Dyck


Reginald Blue

unread,
Feb 22, 2001, 4:08:26 PM2/22/01
to
No and yes.

No, because, if a .c file is supposed to be the C programming language then,
of course not, because C doesn't support things like "new".

Yes, because you can override which compiler is called for any code module.
Just tell it to invoke the C++ compiler. (Select the file, right click,
settings, Genera, always use custom build, set the command line manually.)
I really am not actually recommending this, but perhaps you have a good
reason to write confusing, hard to maintain code.

(i.e. call it what it is...use a cpp extension.)

BTW, main returns int, not void.

--
Reginald Blue | Opinions expressed here do not
Natural Language Understanding | necessarily represent those of
Unisys Corporation | my employer.
--------------------------------+-------------------------------
For speech technology solutions,| r...@NOSPAM.trsvr.tr.unisys.com
NL technology,speech application| My email address is wrong, you
development training, see: | need to remove the obvious.
http://www.speechdepot.com/ +-------------------------------


"Chris Dyck" <vcd...@home.com> wrote in message
news:HPel6.214952$KP3.53...@news3.rdc1.on.home.com...

0 new messages