c++,map,externRelated issues-Collection of common programming errors


  • rcwaldron
    c++ visual-c++
    I’m trying to compile this code using MS Visual Studio Professional 2010 and it’s giving me a build error LNK1120 Fatal Error: 1 unresolved externals. Here’s the code…// Program Typos prints three integer numbers, sums the numbers, calculates // the average, and prints the sum and the average of the three numbers.#include <iostream> #include <iomanip> using namespace std;const int ONE = 5; const int TWO = 6; const int THREE = 7;int main () {int sum;float average;cout << fixe

  • Loom
    c++ exception-handling exception logging
    I have some function like:void foo() { … }int main() {…try {…foo();…} catch (const std::exception &e) {std::cout << “Fatal error: e.what() << std::endl();return;}… }If an exception is thrown from foo, I’d like to know it. Also I want to know the reason of the original exception. I can split the code like this:int main() {… try {… } catch (const std::exception &e) {std::cout << “Fatal error: ” << e.what() << std::endl;return;}try {foo();} catch

  • Tom Wijsman
    c++ source-check
    Do you think that the criticisms in Frequently Questioned Answers are accurate?

  • MichaelT
    design c++ logging
    Recently my team has programmed a custom developer console in a video game which can easily be hidden or displayed, because it’s more comfortable and less of a hassle.The Console class contains a log(string) function which should be easily accessible from anywhere outside of it, without having to reference it everywhere.How could we design a method that can be easily accessed from the outside of the class? For example printing a message to the console in C++ is as simple as:cout << “Messag

  • Lex
    c++ debugging error-handling assertions
    I am a big fan of writing assert checks in C++ code as a way to catch cases during development that cannot possibly happen but do happen because of logic bugs in my program. This is a good practice in general.However, I’ve noticed that some functions I write (which are part of a complex class) have 5+ asserts which feels like it could potentially be a bad programming practice, in terms of readability and maintainability. I think it’s still great, as each one requires me to think about pre- and p

  • luk32
    c++ design-patterns logging design
    Hi I have fairly complex program that is doing computations in a quite large loop. I want to log some basic statistic about the run to be able to analyze its performance over time and vs loop number. For now I am outputting a set of numbers, about 5 or 6, each loop.The problem is the number of loops is quite large so the log files are big. Also putting 10^6 of measurement points on a plot is kind of pointless.I thought of “filtering” the results by for example printing every 1k’th loop but I wou

  • Potatoswatter
    c++ design design-patterns
    I have this existing code where they have a class and an initialization method in that class. It is expected that once the object of the class is created, they need to call initialize on it.Reason why the initialize method exist The object gets created early to have a global scope and then the initialize method gets called later after loading a dll which it depends on.Issue with having the initialize The class now has this bool isInitialized which needs to be checked in every method before it p

  • m_goldberg
    mathlink c++
    I am trying to create a GUI using Microsoft Visual Studio C++ 2010 by calling Mathematica in my codes. I have done everything step by step as mentioned hereThen I wrote this code as mentioned in hereThe code is as below#include <mathlink.h> #include <stdio.h>int main(int argc, char *argv[]) {MLENV env;MLINK link;int errno;env = MLInitialize(0);link = MLOpenArgcArgv(env, argc, argv, &errno);MLActivate(link);return 0; }The error I get is:1>—— Build started: Project: mathemat

  • Tetrad
    c++ geometry allegro win32
    I get the following error(s) on my program that captures the mouse and then draws a line. Errors:1>—— Build started: Project: Capture_Mouse_Line, Configuration: Debug Win32 —— 1> main.cpp 1>main.obj : error LNK2001: unresolved external symbol “public: static long * Line::yc2” (?yc2@Line@@2PAJA) 1>main.obj : error LNK2001: unresolved external symbol “public: static long * Line::xc2” (?xc2@Line@@2PAJA) 1>main.obj : error LNK2001: unresolved external symbol “public: static l

  • sm4
    c++ opengl sdl
    So I’m trying to write a simple application with SDL 1.2 and OpenGL. This a stripped down version of the code containing the one problem I’m having.//The headers #include “SDL.h” #include “SDL_opengl.h”//Screen attributes const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; const int SCREEN_BPP = 32;//Event handler SDL_Event event;bool initGL() {//Initialize Projection MatrixglMatrixMode( GL_PROJECTION );glLoadIdentity();//Initialize Modelview MatrixglMatrixMode( GL_MODELVIEW );glLoadIde

  • user3157810
    java hadoop map reduce
    I am running following mapreduce program in java it compile successfully but getting at runtime I am using Hortonworks HDP2.0 on EC2.package edu.osu.cse.ysmart.TestQuery;import java.io.IOException;import java.util.*;import java.text.*;import org.apache.hadoop.fs.Path;import org.apache.hadoop.conf.*;import org.apache.hadoop.io.*;import org.apache.hadoop.util.Tool;import org.apache.hadoop.util.ToolRunner;import org.apache.hadoop.mapreduce.Job;import org.apache.hadoop.mapreduce.Mapper;import org.a

  • user1585111
    sorting hadoop map mapreduce reduce
    im just a beginner in hadoop.im getting null pointer exception while performing seconday sortThis is my mapper classpublic void map(LongWritable key, Text value,OutputCollector<Text, Employee> outputCollector, Reporter reporter)throws IOException {// TODO Auto-generated method stubString employeeId = value.toString().split(“,”)[0];String employeeName= value.toString().split(“,”)[1];String employeeDept= value.toString().split(“,”)[2];String employeejoinDate= value.toString().split(“,”)[3];S

  • Raghav Sood
    android map
    Hello I am trying to create an app that shows where you are in a facility. First I made it tell me my longitude and latitude. Then I made the background of the app a picture of the facility and made a symbol that went on top of the map (that would later become the symbol that represents where you are but at first I just gave it random numbers to place it somewhere on the map to make sure it worked). Then when trying to enter the coordinates for the symbol it crashes and force closes as soon as t

  • user1078261
    java json map hashmap jackson
    I’m using Jackson to deserialize a json file (that I serialized with jackson). The json is a simple HashMap, but the mapper is complaining when I try and deserialize.org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.HashMap out of START_ARRAY tokenMy serialized HashMap string…..{ “0f861a9a-0a3e-40a7-8ff3-0b83d8070876” : { “name” : “BAR.xml”, “filePath” : “/FOO/repo/BAR.xml” }, “f3cbb32e-b7b8-4af1-b48b-7ea393de7971” : { “name” : “BLAH.xml”, “filePath” :

  • trh178
    ruby map shorthand
    I am aware of the shorthand for map that looks like:[1, 2, 3, 4].map(&:to_s) > [“1”, “2”, “3”, “4”]I was told this is shorthand for:[1, 2, 3, 4].map{|i| i.to_s}This makes perfect sense. My question is this: It seems there should be an easier way to write:[1, 2, 3, 4].map{|x| f.call(x)} for some procedure f. I know the way I just typed isn’t all that long to begin with, but I’d contend that neither is the previous example for which the shorthand exists. This example just seems like the com

  • jaisonDavis
    android google-maps map google-maps-api-2
    I am trying to get a basic map application to work but, I am getting only the grid screen.Code:1.ActivityMain.javaimport android.os.Bundle; import com.google.android.maps.MapActivity; import com.google.android.maps.MapView; public class MainActivity extends MapActivity {MapView mapView;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);mapView = (MapView) findViewById(R.id.map_view); }@Overrideprotected boole

  • koolness
    jquery-ajax map youtube-api jsonp done
    I’m retrieving Youtube video thumbnails and such with a function that deals with comma-delimited string of video IDs :function videoIDs(){ var videoArray = $(“#comma-delimited-IDs”).val().split(“,”); var defArray = $.map(videoArray, function (videoIDs) { var requestURLs = ‘//gdata.youtube.com/feeds/api/videos/’+ videoIDs +’?v=2& format=5alt=json-in-script&callback=?’; return $.ajax({ type: “get”, dataType: “jsonp”, url: requestURLs, success: function(data) {} }); }); $.when.apply(null,de

  • user2328204
    map reduce
    I tried to execute the example from the Penatho Website http://wiki.pentaho.com/display/BAD/Using+Pentaho+MapReduce+to+Generate+an+Aggregate+Dataset+in+MapRwith the following error. It works for a my friend no problem at all on the same Hadoop Cluster.013/04/27 16:19:29 – Pentaho MapReduce – Configuring Pentaho MapReduce job to use Kettle installation from /opt/pentaho/mapreduce/4.4.0-1.3.0-cdh4 2013/04/27 16:19:57 – Pentaho MapReduce – Setup Complete: 0.0 Mapper Completion: 0.0 Reducer Completi

  • Karussell
    android map openstreetmap
    I’m using osmosis to conver OSM map file to *.map to use with mapsfroge in android. I installed the plugin through these steps:1) copy ‘mapsforge-map-writer-0.3.0-jar-with-dependencies.jar’ into’osmosis/lib/default’ directory2) Create file ‘osmosis-plugins.conf’ into ‘osmosis/config’ directory3) Add this line to the file:org.mapsforge.map.writer.osmosis.MapFileWriterPluginLoader Now, when using this line : osmosis –rb file=tehran.osm.pbf –mapfile-writer file=tehran.map type=hdI got this :. .`S

  • Anand Degwekar
    list haskell map time-complexity
    Sorry if this seems like an obvious question.I was creating a Data.map of lists {actually a tuple of an integer and a list (Integer, [(Integer, Integer)])} for implementing a priority queue + adjacency list for some graph algorithms like Dijkstras and Prims, The Data.map is implemented using binary trees(I read that) so I just want to confirm that when doing the map operations (I believe they will be rotations) the interpreter does not do deep copies of the list just shallow copies of the refere

  • gct
    c++ dll namespaces extern
    I’m working on getting rLog to build as a DLL under windows, and I was getting undefined symbol errors relating to some global symbols in the rlog namespace. Specifically these in RLogChannel.cpp:namespace rlog { …RLogChannel *_RLDebugChannel = GetGlobalChannel( “debug”, Log_Debug );RLogChannel *_RLInfoChannel = GetGlobalChannel( “info”, Log_Info );RLogChannel *_RLWarningChannel = GetGlobalChannel( “warning”, Log_Warning );RLogChannel *_RLErrorChannel = GetGlobalChannel( “error”,

  • shinozaki
    c++ class virtual extern
    I’ve been developing in C++ for some time when I was a student, but I never used virtual class or extern in C++ in any of the projects. I just recent read about these two, and was hoping if someone had a better understanding of their usage.What is the purpose of virtual class? An example of where it could be used/implemented. I gloss over it a bit on IBM website and wrote a test program to see it in action, but when would it be good to use a virtual class?The same goes for extern as well. I saw

  • Fracu
    qt memory-leaks pthreads extern
    I’m having an issue with a program that uses pthread under Qt.Since I started using an external library I’m dealing with a strange memory leak.To represent the problem I prepare this simple example:extern “C” short __stdcall somefunction(some_parameters);void *runThread( void *arg ){printf(“I’m a thread…\n”);pthread_exit(NULL);}int main(){somefunction(some_parameters);pthread_t thread;pthread_attr_t attr;while(1){pthread_attr_init(&attr);pthread_attr_setdetachstate(&attr, PTHREAD_CREAT

  • bkaid
    c++ dll linker extern
    I am using __declspec(dllimport/export) on a debug version of new as such:#ifdef _DEBUGDECLSPECCORE extern void* operator new(unsigned int size, const char* file, int line);extern void* operator new[](unsigned int size, const char* file, int line);extern void operator delete(void* address, const char* file, int line);extern void operator delete[](void* address, const char* file, int line);extern void Delete(void* address);#define LUDO_NEW new(__FILE__, __LINE__) #define LUDO_DELETE delete#endi

  • Nikhil J Joshi
    c++ const extern
    I have a header (only) file constants.h, where I define all the constant variables, to be used later in the library. However, there is one variable, which I would like to define run-time in an implementation file. I tried to do something like this:constant.hppextern const unsigned int numTests;somewhere else in run.cppconst unsigned int numTests = 10;and, then yet another file tester.cpp usesif ( n < numTests) {// do something}Now, when I compile it, I get a linker error in tester.o as undefi

  • drcyber
    c++ variable-scope extern
    I have the following program in two filesmain.cppfloat POW10[300];main(0{Fill_POW10();}Fill.cppextern float *POW10; Fill_POW10() {for(int i=0;i<300;i++){POW10[i]=i;} }This crashed with a segmentation fault. When I inspect, POW10 is NULL. However if I change Fill.cpp toextern float POW10[]; Fill_POW10() {for(int i=0;i<300;i++){POW10[i]=i;} }the code works fine. I was thinking that POW10 is actually implemented as a pointer to floats and so the codes should be identical. Can you please expla

  • Viktor Lexington
    c extern linkage
    This question already has an answer here:How do I share a variable between source files in C? With `extern`, but how?11 answersWhy should I use the extern keyword in the following code:header.hfloat kFloat; // some say I should write ‘extern float kFloat;’, but why?file.c#include <stdio.h> #include “Header.h”float kFloat = 11.0f;main.c#include <stdio.h> #include “Header.h”int main(int argc, const char * argv[]) {printf(“The global var is %.1f\n”, kFloat);return 0; }This code works. T

  • Alladinian
    iphone objective-c ios extern
    I have the following code where I am passing the value of buttonString (an NSString) to another view controller. the app crashes when buttonString = imageName; is set and then called on the other view controller.in the .h file of the FirstViewController before the @interface:extern NSString* buttonString;in the .m file of the FirstViewController before the implementation: NSString* buttonString = nil;and here’s the code:NSString *imageName = [NSString stringWithFormat:@”myImage_%d.png”, sele

  • Scott Lawton
    jquery-plugins extern google-closure-compiler
    I created an externs file to be able to compile the jQuery Star Rating Plugin fyneworks.com/jquery/star-rating/#tab-Testing with Google Closure Compiler’s ADVANCED_OPTIMIZATIONS.But, even though I reference the standard jQuery extern, the ‘$’ is getting renamed which breaks the plugin.Perhaps related: if I use the unmodified plugin, ‘rating’ also gets renamed. I can fix that part with:$.fn[‘rating’] = function(opts) {from google closure compile jQuery Plugin … but that doesn’t fix ‘$’ (and it

  • Rüppell’s Vulture
    c global-variables extern linkage storage-class-specifier
    Here I have two files externdemo1.c and externdemo2.c.In the first file,I have declared and initialized a character array arr at file scope.But I have declared it in the second file externdemo2.c without the extern keyword and made use of it there in the function display(). Here are my confusions arising from it.Please answer these three://File No.1–externdemo1.c#include<stdio.h> #include “externdemo2.c”extern int display(); char arr[3]={‘3′,’4′,’7’}; //extern char arr[3]={‘3′,’4′,’7’};//

Web site is in building