小编Alo*_*ave的帖子

c ++"没有匹配的函数来调用

当我尝试传入一个数组作为参数时,我得到:

"No matching function to call to ' table::retrieve(const char[16], item&, int)'
Run Code Online (Sandbox Code Playgroud)

我试图用这个函数调用

program.reference.retrieve("Abecean Longfin", program.client_item, 1);
Run Code Online (Sandbox Code Playgroud)

功能是

int table::retrieve(char item_in[],item*item_list, int name_flag)
Run Code Online (Sandbox Code Playgroud)

我确信这是一件我不理解的简单事情,但我是新手.

c++ arrays pointers parameter-passing

1
推荐指数
1
解决办法
1090
查看次数

C++中的LNK2019错误

我收到这个奇怪的链接器错误:

Error   1   error LNK2019: unresolved external symbol "public: virtual __thiscall Data::~Data(void)" (??1Data@@UAE@XZ) referenced in function "public: virtual __thiscall Job::~Job(void)" (??1Job@@UAE@XZ) C:\...\Job.obj

Error   2   error LNK2019: unresolved external symbol "public: __thiscall List::DataNode::DataNode(class List::DataNode const &)" (??0DataNode@List@@QAE@ABV01@@Z) referenced in function "public: __thiscall List::List(class List const *)" (??0List@@QAE@PBV0@@Z)    C:\...\List.obj
Run Code Online (Sandbox Code Playgroud)

从第一个错误描述中,它可能与析构函数有关.

我有一个带有纯虚析构函数的空和抽象数据类:

virtual ~Data()=0;
Run Code Online (Sandbox Code Playgroud)

和一个派生自数据的类,带有一个简单的析构函数实现:

Job::~Job()
{
}
Run Code Online (Sandbox Code Playgroud)

你能发现问题吗?我该如何解决?谢谢!

c++

1
推荐指数
1
解决办法
252
查看次数

如何在C++中更改变量的常量?

以下是我的代码

const int i = 10;
cout<<i<<"\n";
int *ip = (int*)&i;
*ip = 20;
cout<<i<<"\n";
Run Code Online (Sandbox Code Playgroud)

我期待输出1020.
但我得到输出1010.

我能够编译程序,我没有在编译时或运行时得到任何错误,但没有得到预期的结果.如果我删除了变量i的常量,为什么新值没有分配给它?

如果有人能够解释发生了什么以及可以做些什么来实现我的预期结果,我将不胜感激.

c++ const

1
推荐指数
1
解决办法
1930
查看次数

String Class Error,不能在Class中添加

字符串类在我的电脑中不起作用?这是我的代码,我讨厌在它上面创建一个项目,是否有任何语法错误,我的书使用的确如此,问题是什么?

#include <string>
#ifndef LAB_PROJECT_H
#define LAB_PROJECT_H


struct Node
{
  Node* nextptr;
  Node* prevptr;
  string student_name;
  string father_name;
  int registration;
  string section;
  string major;
 string area;
 };
Run Code Online (Sandbox Code Playgroud)

c++

1
推荐指数
1
解决办法
43
查看次数

有趣的C++代码片段,有什么解释吗?

可能重复:
为什么我能够使用无效的类指针进行函数调用

class B
{
    public:
    int i;
    B():i(0){}
    void func1()
    {
        cout<<“func1::B\n”;
    }
    void func2()
    {
        cout<<“i = “<<i;
    } 
};


int main()
{

    B *bp = new B;

    bp->func1();

    delete bp;

    bp = NULL;

    bp->func1();
    bp->func2();

    return 1; 
}
Run Code Online (Sandbox Code Playgroud)

输出:

func1::B 
func1::B 
Runtime Exception:
NULL pointer access
Run Code Online (Sandbox Code Playgroud)

c++ null

0
推荐指数
2
解决办法
551
查看次数

c ++构造函数问题

我仍然对CTORs感到困惑:

问题1:
为什么第15行呼叫A:A(int)而不是A:A(double&)

问题2:
为什么18号线没有打电话A:A(B&)

#include <iostream>
using namespace std;

class B{};

class A{
public:
   A(int )    {cout<<"A::A(int)"<<endl;}
   A(double&){cout<<"A::A(double&)"<<endl;} // it will work if it is A(double), without the &
   A(B&){cout<<"A::A(B&)"<<endl;}
};

int main()
{
/*line 15*/   A obj((double)2.1);  // this will call A(int), why?
   B obj2;
   A obj3(obj2);
/*line 18*/   A obj4(B);          // this did not trigger any output why?
}
Run Code Online (Sandbox Code Playgroud)

c++ constructor

0
推荐指数
1
解决办法
115
查看次数

在复制构造函数中表示什么?

#include <iostream>

using namespace std;

class tester {
public:
int a;
tester( int x ) {
    a = x;
}

tester( tester &t ) {
    cout << t.a;
}
};

int main() {
 tester t(10);
 tester t_1(t);
}

output : 10
Run Code Online (Sandbox Code Playgroud)

在复制构造函数的定义中t引用了什么?从main传入t参数时t_1,它的地址被存储在&t复制构造函数的表单中.什么t.a意思?

c++ constructor copy-constructor

0
推荐指数
1
解决办法
159
查看次数

在readed之前更改标识符的后缀?

我真的不知道后缀.我知道它首先使用标识符然后增加或减少,如第一次显示i然后++.但现在我认为我错了,仍然不明白.

#include <iostream>

using namespace std;

int main()
{
    int i = 0;
    cout << i << i++ << i;
    cout << "\n\n\nPress Enter to close the window . . . ";
    cin.clear();
    cin.sync();
    cin.get();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

101


Press Enter to close the window . . . 
Run Code Online (Sandbox Code Playgroud)

首先i在增量加入之前改变.为什么?

我期望

001

Press Enter to close the window . . .
Run Code Online (Sandbox Code Playgroud)

有人可以解释.

c++

0
推荐指数
1
解决办法
80
查看次数

C++:垃圾收集

我有一个代码:

class A{
public:
void method1 (){
// do something
}
};

class B{
public:
void method2 (){
// do something
}
};

main(int argc, char* argv[])
{
A a ;
a.method1();
// free object a
B b ;
b.method2();
}
Run Code Online (Sandbox Code Playgroud)

现在,在创建b对象之前,我希望释放一个由a占用的内存.任何人都可以帮我怎么做?

c++

0
推荐指数
1
解决办法
609
查看次数

为什么编译器不会抱怨访问超出动态数组边界的元素?

我正在定义一个大小为9的数组.但是当我访问数组索引10时,它没有给出任何错误.

int main() {
   bool* isSeedPos = new bool[9];
   isSeedPos[10] = true;
}
Run Code Online (Sandbox Code Playgroud)

我期望得到编译器错误,因为isSeedPos[10]我的数组中没有数组元素.

为什么我没有收到错误?

c++

-1
推荐指数
1
解决办法
579
查看次数