jjzjj

c - "Error: unknown type name ..."在处理与二级 ADT 融合的一级 ADT 时。

coder 2024-06-14 原文

大家早上好

我是 SO 的新手,我问这个问题是因为我必须重新调整昨天的算法和编程考试。 在 CodeBlocks 上输入我的考试时,我遇到了一个我无法修复的错误。基本上,考试要求从数据结构中的文件(格式:char *namecity, int population, int distance)中加载内存中的一些信息,然后它要求计算每个城市的相互距离并将它们收集到另一个数据中结构体。我决定制作 2 个 ADT:第一个在我的库“vett.h”中定义:

#ifndef VETT_H_INCLUDED
#define VETT_H_INCLUDED
#include "List.h"

typedef struct vett
{
    char nome[21];
    int abitanti, dist;
    lista_t List;
} Item;

Item *vectInit(int N, Item *v);
Item *vectInsert(Item *v, char *nome, int people, int dist, int i);
#endif // VETT_H_INCLUDED

我根据老师的类(class)做了一个“几乎是 ADT”或“二级 ADT”(R.Sedgewick)。这样做,main 可以为该结构创建一个数组,并且可以直接访问该结构的字段;每个“单元格”包含:城市名称、人口、距离和一个列表类型字段。问题从这里开始。 为了计算和保存城市间的相互距离,我决定在名为“List.h”的库中制作另一个 ADT 列表,类型为 1st class:

#ifndef LIST_H_INCLUDED
#define LIST_H_INCLUDED

#include "vett.h"

typedef struct lista *lista_t;

lista_t calculateMutualDistance(lista_t List, Item *v, int N, int dist);
int chechForBetter(int SD, int i, int N, Item *v);
lista_t listInit(lista_t List, int N);

#endif // LIST_H_INCLUDED`

文件“List.c”包含 .h 文件中指向的结构:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "List.h"

typedef struct node *Node;
struct node
{
    char destination[21];
    int distance;
    Node next;
};

struct lista
{
    Node head, tail;
};

(...)

现在我从 CodeBlocks 得到这个错误(在 vett.h 中,第 9 行,在 int abitanti,int dist 之后):

“错误:未知类型名称‘lista_t’”。

但是为什么? lista_t 包含在 List.c 文件中,应该从“vett.h”中完全可见,因为我包含了“List.h”并且指针在“List.c”中找到了它的结构,它有“List.h”也包括在内!

希望有人能给我解释一下,因为我只有 2 天的时间来调整程序并使其运行,而且时间非常长。感谢您的关注并为我的语法错误感到抱歉,因为您可以看出我不是英语。祝你有美好的一天!

最佳答案

这通常是前向声明问题。只需像这样更改您的 List.h 文件:

#ifndef LIST_H_INCLUDED
#define LIST_H_INCLUDED

typedef struct vett Item;
typedef struct lista *lista_t;

lista_t calculateMutualDistance(lista_t List, Item *v, int N, int dist);
int chechForBetter(int SD, int i, int N, Item *v);
lista_t listInit(lista_t List, int N);

#endif // LIST_H_INCLUDED`

关于c - "Error: unknown type name ..."在处理与二级 ADT 融合的一级 ADT 时。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35033220/

有关c - "Error: unknown type name ..."在处理与二级 ADT 融合的一级 ADT 时。的更多相关文章

  1. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  2. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  3. ruby-on-rails - Ruby on Rails : . 常量化 : wrong constant name error? - 2

    我正在使用这个:4.times{|i|assert_not_equal("content#{i+2}".constantize,object.first_content)}我之前声明过局部变量content1content2content3content4content5我得到的错误NameError:wrongconstantnamecontent2这个错误是什么意思?我很确定我想要content2=\ 最佳答案 你必须用一个大字母来调用ruby​​常量:Content2而不是content2。Aconstantnamestart

  4. ruby - 如何指定 Rack 处理程序 - 2

    Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack

  5. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  6. ruby-on-rails - 迷你测试错误 : "NameError: uninitialized constant" - 2

    我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test

  7. ruby-on-rails - 相关表上的范围为 "WHERE ... LIKE" - 2

    我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que

  8. 使用 ACL 调用 upload_file 时出现 Ruby S3 "Access Denied"错误 - 2

    我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file

  9. ruby-on-rails - 错误 : Error installing pg: ERROR: Failed to build gem native extension - 2

    我克隆了一个rails仓库,我现在正尝试捆绑安装背景:OSXElCapitanruby2.2.3p173(2015-08-18修订版51636)[x86_64-darwin15]rails-v在您的Gemfile中列出的或native可用的任何gem源中找不到gem'pg(>=0)ruby​​'。运行bundleinstall以安装缺少的gem。bundleinstallFetchinggemmetadatafromhttps://rubygems.org/............Fetchingversionmetadatafromhttps://rubygems.org/...Fe

  10. ruby - 安装 Ruby 时遇到问题(无法下载资源 "readline--patch") - 2

    当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub

随机推荐