【问题标题】:Makefile, C++ build error: forward declarationMakefile,C++ 构建错误:前向声明
【发布时间】:2014-10-24 04:26:02
【问题描述】:

您好,我正在使用 make 实用程序将结构 var 传递给另一个文件函数,我遇到错误 ppz 帮助修复它

1) var 的类型不完整 2) header.h:error: struct st 的前向声明

代码如下:

header.h

#include<iostream>
#include<stdio.h>

using namespace std;

void fn(struct st);

main.cpp

#include"header.h"

struct st
{
  int x;
  char s[10];
};

fn.cpp

#include"header.h"

void fn(struct st var)
{
  cout<<var.x<<var.s<<endl;
}

制作文件

all: hello
hello: main.o fn.o
    g++ main.cpp fn.cpp

main.o: main.cpp
    g++ -c main.cpp

fn.o:fn.cpp
    g++ -c fn.cpp

【问题讨论】:

    标签: c++ makefile structure


    【解决方案1】:

    将 struct st 声明移动到 header.h,在 fn() 之前。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 2011-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多