致命错误LNK1169:找到一个或多个多重定义符号(C++)
fatal error LNK1169: one or more multiply defined symbols found (C++)
我正试图编译此代码,但我得到了致命错误LNK1169:找到了一个或多个多重定义符号。这段代码只是一个测试,看看C++指针是如何工作的。请告诉我代码出了什么问题。谢谢
#include <iostream>
using namespace std;
int main()
{
//PROBLEM 8.8
//8.8 (a) Declare an array of type unsigned int called values with five elements, and initialize
//the elements to the even integers from 2 to 10. Assume that the symbolic constant SIZE
//has been defined as 5.
unsigned const int SIZE = 5;
unsigned int values[SIZE] = { 2, 4, 6, 8, 10 };
//8.8 (b) Declare a pointer vPtr that points to an object of type unsigned int.
unsigned int *vPtr;
//8.8 (c) Use a for statement to print the elements of array values using array subscript notation.
for (int i = 0; i < SIZE; i++){
cout << values[i] << endl;
}
//8.8 (d) Write two separate statements that assign the starting address of array values to pointer
//variable vPtr.
vPtr = values;
vPtr = &values[0];
//8.8 (e) Use a for statement to print the elements of array values using pointer/offset notation.
for (int i = 0; i < SIZE; i++){
cout << *(vPtr + i) << endl;
}
//8.8 (f) Use a for statement to print the elements of array values using pointer/offset notation
//with the array name as the pointer.
for (int i = 0; i < SIZE; i++){
cout << *(values + i) << endl;
}
//8.8 (g) Use a for statement to print the elements of array values by subscripting the pointer to
//the array.
for (int i = 0; i < SIZE; i++){
cout << (vPtr[i]) << endl;
}
//8.8 (h) Refer to the fifth element of values using array subscript notation, pointer/offset notation
//with the array name as the pointer, pointer subscript notation and pointer/offset
//notation.
cout << values[4] << endl;
cout << *(vPtr + 4) << endl;
cout << *(values + 4) << endl;
cout << vPtr[4] << endl;
//8.8 (i) What address is referenced by vPtr + 3? What value is stored at that location?
//Address: 1002506; 8 is stored;
cout << (vPtr + 3) << endl;
cout << *(vPtr + 3) << endl;
//8.8 (j) Assuming that vPtr points to values[ 4 ], what address is referenced by vPtr -= 4?
//What value is stored at that location?
//Address: 1002500; 2 is stored;
unsigned int *temp = vPtr;
cout << (vPtr -= 4) << endl;
cout << *(temp -= 4) << endl;
//PROBLEM 8.9
//8.9 (a) Declare the variable longPtr to be a pointer to an object of type long.
long *longPtr;
//8.9 (b) Assign the address of variable value1 to pointer variable longPtr.
long value1 = 200000;
long value2;
longPtr = &value1;
//8.9 (c) Print the value of the object pointed to by longPtr.
cout << *longPtr << endl;
//8.9 (d) Assign the value of the object pointed to by longPtr to variable value2.
value2 = *longPtr;
//8.9 (e) Print the value of value2.
cout << value2 << endl;
//8.9 (f) Print the address of value1.
cout << &value1 << endl;
//8.9 (g) Print the address stored in longPtr. Is the value printed the same as value1’s address?
cout << longPtr << endl; //Yes, it's the same.
}
问题中发布的代码对我来说很好(我无法在此处复制任何链接器错误)。
您可能在同一项目中有其他使用相同符号(包括main()
)的.cpp
文件。
相关文章:
- 是否可以使用单个定义定义函数的常量和常规版本?(使用模板,自动,decltype等)
- 带有限定符的函数类型定义用例
- 有没有办法构建C++自定义限定符?
- 使用无效指针初始化指针声明符的行为是否未定义?
- 从一个函数和某些类型指定符定义整个派生类的宏
- TensorFlow类占位符以及其他定义输入张量的方法
- Eclipse CDT将方法定义定义到标头文件
- 读取文件内容时未定义的字符,文件末尾没有换行符
- 增强自定义权重到boost :: grid_graph中的边缘描述符
- 为什么编译器需要在已经类限定的成员函数定义的返回类型上使用类限定符
- C++ 错误 C2373 重新定义不同的类型修饰符
- 声明和定义之间常量限定符的使用不一致
- 如何从一组已定义的描述符动态构建新的 protobuf
- CTOR 声明/定义中接受的 const 限定符(LLVM 错误?)
- 运算符 +' : 重定义;不同类型的修饰符
- LEX 程序中的未定义定义
- 如何避免SOCI错误:提取了Null值,但未定义指示符
- 在编译时自定义/重写符号名
- 如何为流化自写类编写用户定义操纵符
- c++,将自定义占位符与函数参数匹配