Problem in transform function
-
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
-
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
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
-
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
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\_;
};
-
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\_;
};
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 codeJava, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
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 codeJava, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
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.
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
-
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.
Sorry, the declaration before main is
template std::pairPC::PC\_type,PC std::make_pairPC::PC\_type,PC(PC::PC_type,PC);
-
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
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); -
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);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
-
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
-
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
-
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