Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. + cannot add two pointers, most elegant solution ?

+ cannot add two pointers, most elegant solution ?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ALLERSLIT
    wrote on last edited by
    #1

    Hey, I just came across a little problem and wanted to ask for your guys opinion. What would be the most elegant solution to fix this little issue.

            if (GetDriveType(drv) == DRIVE\_FIXED)
            {
                GetDiskFreeSpaceEx(drv,0,&DiskSpace,&FreeDiskSpace);
                itoa(GetTickCount()/1000%60,ds,10);
                itoa(GetTickCount()/1000%60,fs,10);
                string temp = "test " + ds + " dasd" + fs;
            }
    

    error C2110: '+' : cannot add two pointers Open for any suggestions, greetings !

    D N A 3 Replies Last reply
    0
    • A ALLERSLIT

      Hey, I just came across a little problem and wanted to ask for your guys opinion. What would be the most elegant solution to fix this little issue.

              if (GetDriveType(drv) == DRIVE\_FIXED)
              {
                  GetDiskFreeSpaceEx(drv,0,&DiskSpace,&FreeDiskSpace);
                  itoa(GetTickCount()/1000%60,ds,10);
                  itoa(GetTickCount()/1000%60,fs,10);
                  string temp = "test " + ds + " dasd" + fs;
              }
      

      error C2110: '+' : cannot add two pointers Open for any suggestions, greetings !

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      ALLERSLIT wrote:

      Open for any suggestions, greetings !

      You did not show how ds and fs were declared, but one way might be:

      string temp = string("test ") + ds + string(" dasd") + fs;

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "Man who follows car will be exhausted." - Confucius

      A 1 Reply Last reply
      0
      • D David Crow

        ALLERSLIT wrote:

        Open for any suggestions, greetings !

        You did not show how ds and fs were declared, but one way might be:

        string temp = string("test ") + ds + string(" dasd") + fs;

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "Man who follows car will be exhausted." - Confucius

        A Offline
        A Offline
        ALLERSLIT
        wrote on last edited by
        #3

        Does not work out for me. Getting theese errors:

        Does not work out for me.

        \test\main.cpp(18) : error C2784: 'std::_String_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_iterator<_Elem,_Traits,_Alloc>' from 'char [5]'
        1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(440) : see declaration of 'std::operator +'
        \test\main.cpp(18) : error C2784: 'std::_String_const_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_const_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_const_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_const_iterator<_Elem,_Traits,_Alloc>' from 'char [5]'
        1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(300) : see declaration of 'std::operator +'
        \test\main.cpp(18) : error C2784: 'std::reverse_iterator<_RanIt> std::operator +(_Diff,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'char [5]'
        1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(2203) : see declaration of 'std::operator +'
        \test\main.cpp(18) : error C2784: 'std::_Revranit<_RanIt,_Base> std::operator +(_Diff,const std::_Revranit<_RanIt,_Base> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'char [5]'
        1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(2003) : see declaration of 'std::operator +'
        \test\main.cpp(18) : error C2676: binary '+' : 'std::basic_string<_Elem,_Traits,_Ax>' does not define this operator or a conversion to a type acceptable to the predefined operator

        T 1 Reply Last reply
        0
        • A ALLERSLIT

          Does not work out for me. Getting theese errors:

          Does not work out for me.

          \test\main.cpp(18) : error C2784: 'std::_String_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_iterator<_Elem,_Traits,_Alloc>' from 'char [5]'
          1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(440) : see declaration of 'std::operator +'
          \test\main.cpp(18) : error C2784: 'std::_String_const_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_const_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_const_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_const_iterator<_Elem,_Traits,_Alloc>' from 'char [5]'
          1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(300) : see declaration of 'std::operator +'
          \test\main.cpp(18) : error C2784: 'std::reverse_iterator<_RanIt> std::operator +(_Diff,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'char [5]'
          1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(2203) : see declaration of 'std::operator +'
          \test\main.cpp(18) : error C2784: 'std::_Revranit<_RanIt,_Base> std::operator +(_Diff,const std::_Revranit<_RanIt,_Base> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'char [5]'
          1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(2003) : see declaration of 'std::operator +'
          \test\main.cpp(18) : error C2676: binary '+' : 'std::basic_string<_Elem,_Traits,_Ax>' does not define this operator or a conversion to a type acceptable to the predefined operator

          T Offline
          T Offline
          transoft
          wrote on last edited by
          #4

          string temp = string("test ") + string(ds) + string(" dasd") + string(fs);

          1 Reply Last reply
          0
          • A ALLERSLIT

            Hey, I just came across a little problem and wanted to ask for your guys opinion. What would be the most elegant solution to fix this little issue.

                    if (GetDriveType(drv) == DRIVE\_FIXED)
                    {
                        GetDiskFreeSpaceEx(drv,0,&DiskSpace,&FreeDiskSpace);
                        itoa(GetTickCount()/1000%60,ds,10);
                        itoa(GetTickCount()/1000%60,fs,10);
                        string temp = "test " + ds + " dasd" + fs;
                    }
            

            error C2110: '+' : cannot add two pointers Open for any suggestions, greetings !

            N Offline
            N Offline
            Niklas L
            wrote on last edited by
            #5

            ostringstream os;
            os << "test " << ds << " dasd" << fs;
            string temp = os.str()

            home

            1 Reply Last reply
            0
            • A ALLERSLIT

              Hey, I just came across a little problem and wanted to ask for your guys opinion. What would be the most elegant solution to fix this little issue.

                      if (GetDriveType(drv) == DRIVE\_FIXED)
                      {
                          GetDiskFreeSpaceEx(drv,0,&DiskSpace,&FreeDiskSpace);
                          itoa(GetTickCount()/1000%60,ds,10);
                          itoa(GetTickCount()/1000%60,fs,10);
                          string temp = "test " + ds + " dasd" + fs;
                      }
              

              error C2110: '+' : cannot add two pointers Open for any suggestions, greetings !

              A Offline
              A Offline
              Alain Rist
              wrote on last edited by
              #6

              Hi, This would do the same without ugly and dangerous multiple additions of std::string and const char*:

              #include <sstream>
              // ...
              if (GetDriveType(drv) == DRIVE_FIXED)
              {
              GetDiskFreeSpaceEx(drv,0,&DiskSpace,&FreeDiskSpace);
              std::ostringstream oss;
              oss << "test " << GetTickCount() / 1000 % 60;
              oss << " dasd " << GetTickCount() / 1000 % 60 << std::ends;
              std::string temp = oss.str();
              }

              cheers, AR

              When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

              modified on Saturday, October 30, 2010 2:51 AM

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups