top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

Declaration Error

+1 vote

How do I change the code below so It doesn't have the declaration error. If I change One, Two, Three, Four and Five to numbers and change string to int then the code works. What am I doing wrong?

posted Apr 21 by Ravi Sonigra

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote


are not string object. So I think your code is wrong which is comparing the string object."One") will result 0 if value is equal to "One".

Another option - Enter value in number like 1 , 2, 3 4 and 5 etc.
Compare like this .
value == std::to_string(1);
value == std::to_string(2);
value == std::to_string(3);
value == std::to_string(4);
value == std::to_string(5);

answer Sep 18 by Crazy
0 votes

One is a variable you may need to change One to "One" (with double quotes).

answer Apr 21 by Salil Agrawal
Similar Questions
+1 vote
1)double d=0786; 

2)double d=0x4b17;
–1 vote

I have a c++ shared object that I am compiling using the following command.
g++ -g -Wall -c -o cpplib.o cpplib.cpp

And I am creating the shared object using the following command.
g++ -shared -o cpplib.o

(I am aware that I can do this one single command, these are two separate invocations because I had the project setup on eclipse and that's how eclipse cdt does it.).

My host runs a RedHat 6.x x86_64 OS.

The compilation fails with the following error.

$ g++ -g -Wall -fPIC -c -o cpplib.o cpplib.cpp
$ g++ -shared -fPIC -o cpplib.o
/usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/4.4.7/libstdc++.a(ios_init.o): relocation R_X86_64_32 against `pthread_cancel' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/libstdc++.a: could not read symbols: Bad value
collect2: ld returned 1 exit status

I am certain that I haven't used the 'pthread_cancel' function in my code. Please help me.

+1 vote

I need some help in understanding why my GCC didn't consider this an issue. I have a function that was constructing a path to a daemon program based on the location of the shared object file where this code is. Something similar to this:

namespace {
 std::string ConstructPath()
 int lastSlash(0);
 std::string pathVar;
 Dl_info dl_info;


 pathVar = dl_info.dli_fname;
 lastSlash = pathVar.find_last_of('/');
 if(std::string::npos == lastSlash)
 // no slashes given ... must be that *.so
 // is in the current directory
 pathVar = "mydaemond";
 pathVar.erase(pathVar.begin() + (lastSlash + 1), pathVar.end());

 // first check if we can find the daemon
 // introducing sub-scope to ensure the file object is closed
 std::ifstream test(pathVar.c_str());
 throw std::runtime_error("cannot find mydaemond");

 // *** the below statement wasn't there originally, the
 // *** function simply exited after the forced-scope block above,
 // *** however, the function *did* have the return type
 return pathVar;

My comments above the final return statement illustrate what my question is about. Why wasn't this a problem? There was no return statement and yet, the code compiled fine. I'm using GCC 4.4.4 on CentOS 6.2. Is this just a problem with the 4.4.4 compiler that was fixed? I'm betting there's some subtlety in C++ here that I'm not yet aware of and I'd like to be schooled.

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.