fatal error LNK1169: one or more multiply defined symbols found (C++)

I am trying to compile this code, but I get the fatal error LNK1169: one or more multiply defined symbols found. The code is just a test to see how C++ pointers work. Please tell me what's wrong with the code. Thanks.

#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. }

-------------Problems Reply------------

Your code as posted in the question works fine for me (I cannot reproduce any linker errors here).

You probably have other .cpp files in the same project, that use the same symbols (including main()).

Category:c# Views:3 Time:2015-03-01

Related post

  • Visual C++ 2010 - fatal error LNK1169: one or more multiply defined symbols found 2011-06-28

    this is a program : #include <iostream> using namespace std; int main() { cout << "Enter a number"; int i; cin >> i; try { if( i == 0 ) throw 0; if( i == 2 ) throw "error"; } catch( int i ) { cout << "can't divide by 0"; } cat

  • Using a namespace to make global functions, but getting multiply defined symbols error 2011-08-05

    These functions are Utility type things that most of my programs objects will use. I want to have them in a namespace and have them global. This namespace is defined in a header and then added to my precompiled header. However so far I have used the

  • C++ Multiply defined symbols using a header defined template class 2009-04-16

    I'm working on a project with a DLL and an EXE in visual studio 2005. Amongst the code for the DLL is a template for a growable array class: template <class Type> class GArray { Type *p; uint32 len; uint32 alloc; protected: bool fixed; public:

  • One or more multiply defined symbols found 2011-06-24

    DebugUtil.h #ifndef DEBUG_UTIL_H #define DEBUG_UTIL_H #include <windows.h> int DebugMessage(const char* message) { const int MAX_CHARS = 1023; static char s_buffer[MAX_CHARS+1]; return 0; } #endif When I try to run this I get this error: Terrai

  • Visual Studio 2010 Linker Finding Multiply Defined Symbols (Where It Shouldn't) 2010-04-20

    I've just started with C++, and maybe there's something that I'm doing wrong here, but I'm at a loss. When I try to build the solution, I get 4 LNK2005 errors like this one: error LNK2005: "public: double __thiscall Point::GetX(void)const " ([email protected]

  • How to resolve "LINK : fatal error LNK1561: entry point must be defined"? 2009-07-23

    Guys/gals: How can I resolve the following linking error: "LINK : fatal error LNK1561: entry point must be defined". What I was trying to do is simply recompiling MySQL Storage engine example with Visual Studio 2008. --------------Solutions----------

  • reason for one or more multiply defined symbols found error? 2010-07-21

    here is my code: why does the error "one or more multiply defined symbols found?" #include <stdio.h> #include "person.h" void main() { FILE* census; int status; int data_read; person student[10]; census = fopen("mycensus.dat","r"); if (census =

  • Multiply defined symbols found? 2011-05-20

    I made my own library and compiled it as a static library in MSVC using the MD multithreaded DLL runtime. I then compiled my application and included myLib.lib and when I do I get tons of multiply defined symbols relating to MSVCRTLIB, what am I doin

  • Linker errors 2005 and 1169 (multiply defined symbols) when using CUDA __device__ functions (should be inline by default) 2010-11-16

    This question is very much related to: A) How to separate CUDA code into multiple files B) Link error LNK2005 when trying to compile several CUDA files together Following advice from here: http://meta.stackexchange.com/questions/42343/same-question-b

  • template specialization multiply defined symbols 2010-12-15

    I know i'm missing something easy here but I've got a templated member function of a class which I've specialised. MyClass { template<typename T> T GetTFromVariable(shared_ptr<TOtSimpleVariable> v, string s); } template<typename T>

  • GNU ld: how do I detect multiply-defined symbols? 2012-01-30

    I'm aggregating two very similar sets of source code into a single library archive. There are maybe 5 or 6 functions which are defined with identical signatures in the two code sets, but with slightly different implementation. I need to find these fu

  • Multiply defined structure error 2011-03-13

    I had a big main .cpp file with everything in it .I needed to break the code and so I created a helper.h where I moved all the typedefs, function declarations etc.Now I am trying to move some of the functions from main .cpp into helper.cpp .I had a g

  • Error LNK1169 with Qt Creator 2012-02-04

    first of all, please don't be too hard on me, I am truly a newbie at using Qt and programming is not really my best so I will try to make it as clear as possible. Here is my configuration: Windows XP Visual Studio 2008 Qt 4.7.4 Qt Creator 2.2.1 OpenC

  • visual C++ typdef struct multiple defined symbols problems 2011-09-07

    In Visual C++, i faced "fatal error LNK1169: one or more multiply defined symbols found" with below code, How can i solve the problem if i wanna include both header file in both source for the other functions usage? main.cpp ======== #include main.h

  • When should linkers generate multiply defined X warnings? 2009-09-16

    Never turn your back on C++. It'll getcha. I'm in the habit of writing unit tests for everything I do. As part of this I frequently define classes with names like A and B, in the .cxx of the test to exercise code, safe in the knowledge that i) becaus

  • Dymo software fatal error 2012-05-01

    I have been using the Dymo software 8.5 with a labelwriter 450 twin turbo on my windows 8.1 machine with no problems. All of a sudden when i try to open the softwarwe I get a fatal error "cannont create instance of "mainwindow" defined in assembly 'D

  • Fatal Error on DYMO Printer "Object Reference Not Set To Instance of an object" 2014-04-15

    For 2 months I have been using a DYMO Labelwriter on my desktop at the office. Recently when I attempted to launch the solfware, it gave me a fatal error "Cannot create instance of 'WebBrowser' defined in assembly 'PresentationFramework Version=3.0.0

  • Fatal error: No compiled in support for x86_64 while trying to build qt-4.7.4 with gcc-4.7.2 on 64-bit linux platform 2013-06-01

    Trying to build qt-4.7.4 with gcc-4.7.2 and getting fatal error: no compiled in support for x86_64 during configure. Here is the part of my configure log. Hope the information is enough to help me figure out the problem. Performing shadow build... Pr

  • Use C function in C++ program; "multiply-defined" error 2010-05-02

    I am trying to use this code for the Porter stemming algorithm in a C++ program I've already written. I followed the instructions near the end of the file for using the code as a separate module. I created a file, stem.c, that ends after the definiti

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.192 (s). 11 q(s)