C++에서 C를 사용하는 것은 되는 것으로 알고 있는데... C에서 C++을 사용하는 것이 가능한가요? 예를 들면, C++ 클래스의 오브젝트를 선언한다든가 하는 그런 코딩이 가능한지?
답변 부탁드립니다...
안되죠~
그건 마치 오리지날 스타크래프트에서 다크템플러를 사용할 수 있는가? 와 비슷한 문제로 보이네요 ^^;;;
사용할 수 없습니다. c++에서 c는 사용할 수 있습니다.
물론 정상적인 방법으로는 안 되고, 어셈블 프로그래밍을 해서, 포인터 로, C++언어의 특징들(클래스나, 오버로딩 따위)을 구현해서 쓰는 방법이 있다더군요.
포인터 연산이 복잡하고 짜증나긴 하지만, 방법이 있기는 있데요....물론 컴파일하면 C언어로 컴파일되구요...- -
저는 이런 코드도 씁니다... )
보여주고 나서 이게 C인지 C++인지 참 헤깔리지만요..) ---------cppclass.h--------- #ifndef CPPCLASS_H #define CPPCLASS_H
#include #include
class CPPCLASS { public CPPCLASS() {} ~CPPCLASS() {} void printF(int x) { printf("%d", x ); } }; #endif extern CPPCLASS* temp;
----------main.c #include "cppclass.h" #include
CPPCLASS* temp; int main(int argc, char** argv) { int i; for(i=0; i<100; i++ ) temp->printF(i); return 0; }
--------------- compile는 gcc -o m main.cpp -I. 라고 하면 c에서 temp 객체를 불러올수 있습니다..
거참..C 인지..C++인지... =_=;;
저런 경우가 꼭 필요한 때가 있어서요....쓰고 있습니다만... 왠지... .)
어쨌든...수고하세요..
텍스트 포맷에 대한 자세한 정보
<code>
<blockcode>
<apache>
<applescript>
<autoconf>
<awk>
<bash>
<c>
<cpp>
<css>
<diff>
<drupal5>
<drupal6>
<gdb>
<html>
<html5>
<java>
<javascript>
<ldif>
<lua>
<make>
<mysql>
<perl>
<perl6>
<php>
<pgsql>
<proftpd>
<python>
<reg>
<spec>
<ruby>
<foo>
[foo]
Re: C에서 C++을 사용할 수 있나요?
안되죠~
그건 마치 오리지날 스타크래프트에서 다크템플러를 사용할 수 있는가? 와 비슷한 문제로 보이네요 ^^;;;
Re: C에서 C++을 사용할 수 있나요?
사용할 수 없습니다.
c++에서 c는 사용할 수 있습니다.
Re: C에서 C++을 사용할 수 있나요?
물론 정상적인 방법으로는 안 되고, 어셈블 프로그래밍을 해서, 포인터
로, C++언어의 특징들(클래스나, 오버로딩 따위)을 구현해서 쓰는 방법이
있다더군요.
포인터 연산이 복잡하고 짜증나긴 하지만, 방법이 있기는 있데요....물론
컴파일하면 C언어로 컴파일되구요...- -
Re: C에서 C++을 사용할 수 있나요?
저는 이런 코드도 씁니다... )
보여주고 나서 이게 C인지 C++인지 참 헤깔리지만요..)
---------cppclass.h---------
#ifndef CPPCLASS_H
#define CPPCLASS_H
#include
#include
class CPPCLASS
{
public
CPPCLASS() {}
~CPPCLASS() {}
void printF(int x)
{
printf("%d", x );
}
};
#endif
extern CPPCLASS* temp;
----------main.c
#include "cppclass.h"
#include
CPPCLASS* temp;
int main(int argc, char** argv)
{
int i;
for(i=0; i<100; i++ )
temp->printF(i);
return 0;
}
---------------
compile는
gcc -o m main.cpp -I.
라고 하면 c에서 temp 객체를 불러올수 있습니다..
거참..C 인지..C++인지... =_=;;
저런 경우가 꼭 필요한 때가 있어서요....쓰고 있습니다만...
왠지... .)
어쨌든...수고하세요..
댓글 달기