VC++에서는 되는데 g++에서는 안되는 vector<구조체>

ohhan의 이미지

윈도우에서만 프로그램 짜다가 리눅스에서 돌아가는 것 짜려고 하니깐 잘 안되네요.

문제는 이렇습니다.

link라는 구조체를 만들고 vector a; 라고 선언했습니다.

VC++ 2005에서는 컴파일되고 문제가 없는데, g++ 또는 gcc로 컴파일하려고 하니깐

error: type/value mismatch at argument 1 in template parameter list for ?

template class std::vector ?라는 에러가 납니다.

소스는 요약하면 다음과 같습니다.

#include <vector>
 
using namespace std;
 
 
 
struct link
 
{
 
    int x,  y;
 
}
 
 
 
class my_class 
 
{
 
    public:
 
      ....
 
         vector(link) a;  //꺽쇠가 안먹네요..그래서 대신 괄호로...
 
      ....
 
}

이렇습니다. 답답하네요. 아시는 분 답변 부탁드려요.

neogeo의 이미지

code 라는 tag 를 이용해 코드를 감싸주세요..

소스내용이 안보여서 무슨 질문인지 의도가 파악이 잘 안되네요 :)

g++ 이나 vs2005 나 stl 지원은 완벽한걸로 알고 있습니다.

boost 같은 녀석들이 문제지요 :(

Neogeo - Future is Now.

Neogeo - Future is Now.

ohhan의 이미지

main 함수가 ohhan_main.cpp에
제가 정의한 클래스가 ohhan_alg.cpp 와 ohhan_alg.h 에 있습니다.

이럴 땐 g++로 어떻게 컴파일 하나요?

neogeo의 이미지

cpp 파일을 나열하시면 됩니다.

물론 헤더는 인클루드 가능한 경로에 있어야 하구요. cpp 들과 같은곳에 있지않다면 -I 옵션등을 통해 추가할 수 있습니다.

좀 더 잘 컴파일 하고 싶으시면

Makefile 이라는 것을 이용하시는게 여러모로 유리합니다.

한 번 만들어두면 고쳐가며 두고두고 써먹을 수도 있구요.

cons , scons 등도 괜찮은 컴파일 설정을 관리 할 수 있습니다.

Neogeo - Future is Now.

Neogeo - Future is Now.

ohhan의 이미지

제가 link라는 구조체를 선언했었는데요.
알고보니 link는 g++내에서 예약어였네요...link_nodes로 바꾸니깐 모든게 동작...
이것 때문에 한 5시간동안 삽질했습니다.

dg의 이미지

link는 예약어는 아니고요. unistd.h에 선언된 함수입니다.
g++에서 -E 옵션으로 프리프로세스된 결과를 보니까
만 include해도 가 같이 include가 되버리네요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <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].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <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].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <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].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <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].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.