首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误链接2019

错误链接2019
EN

Stack Overflow用户
提问于 2016-01-22 19:47:58
回答 1查看 2K关注 0票数 0

错误1错误LNK2019:函数_main F:\c++代码\exercise8.42\exercise8.42\Source.obj function 8.42中引用的未解析的外部符号"void __cdecl show(struct __cdecl struct &)“(?void@@YAXABUstringy@Z)

代码语言:javascript
复制
#include<iostream>
#include<cstring>

struct stringy{
    char * str;
    int ct;
};

void set(stringy & r1, char * a);
void show(const stringy & r1);
;

int main()
{
    stringy beany;
    char testing[] = "Reality isn't, and show() go there";
    set(beany, testing);
    show(beany);

    return 0;
}

void set(stringy & r1, char *a)
{
    int i = 0;
    while (a[i] != '\0')
        i++;
    r1.str = new char;
    r1.ct = i;
    for (int b = 0; b < i; b++)
        r1.str[b] = a[b];
    r1.str[i + 1] = '\0';
}

void show(stringy & r1)
{
    std::cout << *r1.str;
}

我刚刚开始使用c++的代码。

EN

回答 1

Stack Overflow用户

发布于 2016-01-22 19:57:10

函数参数的const是该函数签名的一部分。因此

代码语言:javascript
复制
void show(const stringy & r1);

代码语言:javascript
复制
void show(stringy & r1);

在编译main ()时,编译器只知道void show(const stringy & r1);,但是链接器没有找到它的实现,因为您实现了

代码语言:javascript
复制
void show(stringy & r1);

而不是

代码语言:javascript
复制
void show(const stringy & r1);

解决方案只是在stringy & r1实现时在stringy & r1之前添加show

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34954741

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档