当我尝试传入一个数组作为参数时,我得到:
"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)
我确信这是一件我不理解的简单事情,但我是新手.
我收到这个奇怪的链接器错误:
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)
你能发现问题吗?我该如何解决?谢谢!
以下是我的代码
const int i = 10;
cout<<i<<"\n";
int *ip = (int*)&i;
*ip = 20;
cout<<i<<"\n";
Run Code Online (Sandbox Code Playgroud)
我期待输出10和20.
但我得到输出10和10.
我能够编译程序,我没有在编译时或运行时得到任何错误,但没有得到预期的结果.如果我删除了变量i的常量,为什么新值没有分配给它?
如果有人能够解释发生了什么以及可以做些什么来实现我的预期结果,我将不胜感激.
字符串类在我的电脑中不起作用?这是我的代码,我讨厌在它上面创建一个项目,是否有任何语法错误,我的书使用的确如此,问题是什么?
#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) 可能重复:
为什么我能够使用无效的类指针进行函数调用
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) 我仍然对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) #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意思?
我真的不知道后缀.我知道它首先使用标识符然后增加或减少,如第一次显示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)
有人可以解释.
我有一个代码:
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占用的内存.任何人都可以帮我怎么做?
我正在定义一个大小为9的数组.但是当我访问数组索引10时,它没有给出任何错误.
int main() {
bool* isSeedPos = new bool[9];
isSeedPos[10] = true;
}
Run Code Online (Sandbox Code Playgroud)
我期望得到编译器错误,因为isSeedPos[10]我的数组中没有数组元素.
为什么我没有收到错误?