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. ATL / WTL / STL
  4. Problem in transform function

Problem in transform function

Scheduled Pinned Locked Moved ATL / WTL / STL
helpgraphicsdebuggingquestion
12 Posts 2 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
    ashtwin
    wrote on last edited by
    #1

    Hi, i am using transform function to transform a vector to a map but getting the following error. multiMapType.obj : error LNK2001: unresolved external symbol "struct std::pair<enum PC::PC_type,class PC> __cdecl std::make_pair(enum PC::PC_type const &,class PC const &)" (?make_pair@std@@YA?AU?$pair@W4PC_type@PC@@V2@@1@ABW4PC_type@PC@@ABV4@@Z) Debug/MultiMapType.exe : fatal error LNK1120: 1 unresolved externals The code snippet is as follows

    int main( )
    {
    const PC::PC_type kind[] = { PC::IBM,PC::IBM, PC::Dell, PC::HP,PC::HP, PC::HP };

    const int num\_appliances = 3;
    
    vector<PC> v;
    for( int i = 0; i < num\_appliances; ++i )
    	v.push\_back( PC( kind\[i\], i, i ) );
    
    
    // work with a multimap. key is appliance type, value is PC
    typedef multimap<PC::PC\_type,PC> PC\_multimap\_type;
    
    PC\_multimap\_type stock;
    const PC desired( PC::HP );
    
    // load the appliances into the multimap
    **transform( kind, kind+num\_appliances, v.begin(),inserter( stock, stock.end() ),make\_pair<PC::PC\_type,PC> );**	
        PC\_multimap\_type::const\_iterator stock\_end = stock.end();
    
    // search for first occurrence of key
    PC\_multimap\_type::const\_iterator spot = stock.find( desired.appliance() );
    
    if( spot != stock\_end )
    	spot->second.print();
    else
    	cout << "Don't have a " << desired.name() << " in stock\\n";
    return 0;
    

    }

    Please help. Thanks

    S 1 Reply Last reply
    0
    • A ashtwin

      Hi, i am using transform function to transform a vector to a map but getting the following error. multiMapType.obj : error LNK2001: unresolved external symbol "struct std::pair<enum PC::PC_type,class PC> __cdecl std::make_pair(enum PC::PC_type const &,class PC const &)" (?make_pair@std@@YA?AU?$pair@W4PC_type@PC@@V2@@1@ABW4PC_type@PC@@ABV4@@Z) Debug/MultiMapType.exe : fatal error LNK1120: 1 unresolved externals The code snippet is as follows

      int main( )
      {
      const PC::PC_type kind[] = { PC::IBM,PC::IBM, PC::Dell, PC::HP,PC::HP, PC::HP };

      const int num\_appliances = 3;
      
      vector<PC> v;
      for( int i = 0; i < num\_appliances; ++i )
      	v.push\_back( PC( kind\[i\], i, i ) );
      
      
      // work with a multimap. key is appliance type, value is PC
      typedef multimap<PC::PC\_type,PC> PC\_multimap\_type;
      
      PC\_multimap\_type stock;
      const PC desired( PC::HP );
      
      // load the appliances into the multimap
      **transform( kind, kind+num\_appliances, v.begin(),inserter( stock, stock.end() ),make\_pair<PC::PC\_type,PC> );**	
          PC\_multimap\_type::const\_iterator stock\_end = stock.end();
      
      // search for first occurrence of key
      PC\_multimap\_type::const\_iterator spot = stock.find( desired.appliance() );
      
      if( spot != stock\_end )
      	spot->second.print();
      else
      	cout << "Don't have a " << desired.name() << " in stock\\n";
      return 0;
      

      }

      Please help. Thanks

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      Given that I've made assumptions about context (definitions of PC? PC_type? headers you include?), it's difficult to say if I've done the same as you. But your code compiles and links for me under VS2008. What version are you using?

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      A 1 Reply Last reply
      0
      • S Stuart Dootson

        Given that I've made assumptions about context (definitions of PC? PC_type? headers you include?), it's difficult to say if I've done the same as you. But your code compiles and links for me under VS2008. What version are you using?

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

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

        Hi, Thanks for replying. I am using VS98(VC6.0) :) . The headers file and defination of PC is as follows

        #include <algorithm>

        #include <functional>

        #include <iomanip>

        #include <iostream>

        #include <map>

        #include <string>

        #include <utility>

        #include <vector>

        using namespace std;

        class PC

        {

        public:

                enum PC\_type { Dell, HP, IBM, Compaq };
        
                
        
                PC( PC\_type appliance = Dell, int model = 220,
        
                            int serial = 0 );
        
                
        
                bool operator<( const PC& rhs ) const;
        
                
        
                PC\_type appliance() const;
        
                int model() const;
        
                string name() const;
        
                
        
                void print() const;
        
                
        
                int serial() const;
        

        private:

                PC\_type appliance\_;
        
                int model\_;
        
                int serial\_;
        

        };

        S 1 Reply Last reply
        0
        • A ashtwin

          Hi, Thanks for replying. I am using VS98(VC6.0) :) . The headers file and defination of PC is as follows

          #include <algorithm>

          #include <functional>

          #include <iomanip>

          #include <iostream>

          #include <map>

          #include <string>

          #include <utility>

          #include <vector>

          using namespace std;

          class PC

          {

          public:

                  enum PC\_type { Dell, HP, IBM, Compaq };
          
                  
          
                  PC( PC\_type appliance = Dell, int model = 220,
          
                              int serial = 0 );
          
                  
          
                  bool operator<( const PC& rhs ) const;
          
                  
          
                  PC\_type appliance() const;
          
                  int model() const;
          
                  string name() const;
          
                  
          
                  void print() const;
          
                  
          
                  int serial() const;
          

          private:

                  PC\_type appliance\_;
          
                  int model\_;
          
                  int serial\_;
          

          };

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          ashtwin wrote:

          Thanks for replying. I am using VS98(VC6.0)

          My commiserations - VC6 sucks for template usage. Anyway - try declaring the make_pair instance you need before main():

          template std::pairPC::PC\_type,PC std::make_pairPC::PC\_type,PC(PC::PC_type,PC);

          int main( )
          {
          // Rest of your code

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          A 1 Reply Last reply
          0
          • S Stuart Dootson

            ashtwin wrote:

            Thanks for replying. I am using VS98(VC6.0)

            My commiserations - VC6 sucks for template usage. Anyway - try declaring the make_pair instance you need before main():

            template std::pairPC::PC\_type,PC std::make_pairPC::PC\_type,PC(PC::PC_type,PC);

            int main( )
            {
            // Rest of your code

            Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

            A Offline
            A Offline
            ashtwin
            wrote on last edited by
            #5

            Hi, i tried the declaration before main

            template std::pair<PC::PC_type,PC> std::make_pair<PC::PC_type,PC>(PC::PC_type,PC);
            int main( ){

            but still getting the same error. May be some problem in project settings.

            S A 2 Replies Last reply
            0
            • A ashtwin

              Hi, i tried the declaration before main

              template std::pair<PC::PC_type,PC> std::make_pair<PC::PC_type,PC>(PC::PC_type,PC);
              int main( ){

              but still getting the same error. May be some problem in project settings.

              S Offline
              S Offline
              Stuart Dootson
              wrote on last edited by
              #6

              No, shouldn't be project settings. And I don't have VC6 to test with. Oh well.

              Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

              A 1 Reply Last reply
              0
              • A ashtwin

                Hi, i tried the declaration before main

                template std::pair<PC::PC_type,PC> std::make_pair<PC::PC_type,PC>(PC::PC_type,PC);
                int main( ){

                but still getting the same error. May be some problem in project settings.

                A Offline
                A Offline
                ashtwin
                wrote on last edited by
                #7

                Sorry, the declaration before main is

                template std::pairPC::PC\_type,PC std::make_pairPC::PC\_type,PC(PC::PC_type,PC);

                1 Reply Last reply
                0
                • S Stuart Dootson

                  No, shouldn't be project settings. And I don't have VC6 to test with. Oh well.

                  Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                  A Offline
                  A Offline
                  ashtwin
                  wrote on last edited by
                  #8

                  The program is getting build properly if i use a function insted of make_pair in the last parameter of the function transform and return a pair from that function.

                  pair<PC::PC_type, PC> MyFunction(PC::PC_type pcType, PC pc)
                  {
                  return make_pair(pcType, pc);
                  }
                  transform( kind, kind+num_appliances, v.begin(),inserter( stock, stock.end() ),MyFunction);

                  S 1 Reply Last reply
                  0
                  • A ashtwin

                    The program is getting build properly if i use a function insted of make_pair in the last parameter of the function transform and return a pair from that function.

                    pair<PC::PC_type, PC> MyFunction(PC::PC_type pcType, PC pc)
                    {
                    return make_pair(pcType, pc);
                    }
                    transform( kind, kind+num_appliances, v.begin(),inserter( stock, stock.end() ),MyFunction);

                    S Offline
                    S Offline
                    Stuart Dootson
                    wrote on last edited by
                    #9

                    Yes...I should have mentioned that solution :-O In this one, you're not asking the compiler to automatically instantiate a function from the reference in transform, so yes, it includes all the necessary code.

                    Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                    A 1 Reply Last reply
                    0
                    • S Stuart Dootson

                      Yes...I should have mentioned that solution :-O In this one, you're not asking the compiler to automatically instantiate a function from the reference in transform, so yes, it includes all the necessary code.

                      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                      A Offline
                      A Offline
                      ashtwin
                      wrote on last edited by
                      #10

                      Does it mean that whatever i was doing earlier was not correct.

                      S 1 Reply Last reply
                      0
                      • A ashtwin

                        Does it mean that whatever i was doing earlier was not correct.

                        S Offline
                        S Offline
                        Stuart Dootson
                        wrote on last edited by
                        #11

                        Ummm - it should have been correct and OK - but VC6 is a bit rubbish, which is why it didn't work.

                        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                        A 1 Reply Last reply
                        0
                        • S Stuart Dootson

                          Ummm - it should have been correct and OK - but VC6 is a bit rubbish, which is why it didn't work.

                          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                          A Offline
                          A Offline
                          ashtwin
                          wrote on last edited by
                          #12

                          Ok, so the problem is with vc6. Thanks for the help.

                          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