i have written a sample program.below:
#include<iostream>
#include<string>
#include<set>
using namespace std;
int main()
{
std::set<std::string> m;
m.insert("1-2-1-1");
return 0;
}
This works perfectly without any errors.
But i try to create a set and try to insert elemts into it in my application code,it gives me the some errors.
/export/SunStudio/SUNWspro/bin/CC -c -compat=5 -features=no%altspell -features=no%export -mt +d -DTHREAD -DSOLARIS -staticlib=rwtools7 -library=rwtools7,iostream -DOWTOOLKIT_WARNING_DISABLED -Bsymbolic -PIC -g0 -DBPDEBUG -I. -I../nls -I../../cnacore/api -I../../cnacore/external -I../../cnacore/stl -I../../cnabp/kernel -I/vobs/oss_design/sab/inc -I/vobs/oss_design/tbs/inc -I/vobs/oss_design/tss/inc -I/vobs/oss_design/tds/inc -I/vobs/oss_design/eam/inc -I/vobs/ossrc_3pp/cif_3pp/borland_enterprise_server/include -I/vobs/ossrc_3pp/cif_3pp/borland_enterprise_server/include/stubs -I/vobs/ossrc_build_dependencies/extracted_packages/ERICsnlm/include -I/vobs/ossrc_3pp/cif_3pp/sybase_ase/OCS-15_0/include -I/vobs/cna/src/features cacup_bsc.cc
"cacup_bsc.cc", line 6545: Error: Multiple declaration for valid.
"cacup_bsc.cc", line 6545: Error: "," expected instead of ".".
"cacup_bsc.cc", line 6548: Error: Multiple declaration for valid.
"cacup_bsc.cc", line 6548: Error: "," expected instead of ".".
"cacup_bsc.cc", line 6552: Error: std::set_intersection<std::InputIterator1, std::InputIterator2, std::OutputIterator>(std::InputIterator1, std::InputIterator1, std::InputIterator2, std::InputIterator2, std::OutputIterator) is not a static data member.
"cacup_bsc.cc", line 6552: Error: Cannot use std::insert_iterator<std::set<std::string>> to initialize int.
"cacup_bsc.cc", line 8903: Warning: A non-POD object of type "bpDU" passed as a variable argument to function "std::sprintf(char*, const char*, ...)".
"cacup_bsc.cc", line 8906: Warning: A non-POD object of type "bpDU" passed as a variable argument to function "std::sprintf(char*, const char*, ...)".
6 Error(s) and 2 Warning(s) detected.
*** Error code 6
clearmake: Error: Build script failed for "cacup_bsc.o"
below is the code that i have added.
but after commenting the below code.the compilation is successful
/*
std::set<std::string> valid;
valid.insert(string("1-1"));
std::set<std::string> planned;
valid.insert(string("1-1"));
std::set<std::string> result;
std::set_intersection(valid.begin(), valid.end(), planned.begin(), planned.end(), std::inserter(result, result.end()));
*/
/export/SunStudio/SUNWspro/bin/CC -c -compat=5 -features=no%altspell -features=no%export -mt +d -DTHREAD -DSOLARIS -staticlib=rwtools7 -library=rwtools7,iostream -DOWTOOLKIT_WARNING_DISABLED -Bsymbolic -PIC -g0 -DBPDEBUG -I. -I../nls -I../../cnacore/api -I../../cnacore/external -I../../cnacore/stl -I../../cnabp/kernel -I/vobs/oss_design/sab/inc -I/vobs/oss_design/tbs/inc -I/vobs/oss_design/tss/inc -I/vobs/oss_design/tds/inc -I/vobs/oss_design/eam/inc -I/vobs/ossrc_3pp/cif_3pp/borland_enterprise_server/include -I/vobs/ossrc_3pp/cif_3pp/borland_enterprise_server/include/stubs -I/vobs/ossrc_build_dependencies/extracted_packages/ERICsnlm/include -I/vobs/ossrc_3pp/cif_3pp/sybase_ase/OCS-15_0/include -I/vobs/cna/src/features cacup_bsc.cc
"cacup_bsc.cc", line 8902: Warning: A non-POD object of type "bpDU" passed as a variable argument to function "std::sprintf(char*, const char*, ...)".
"cacup_bsc.cc", line 8905: Warning: A non-POD object of type "bpDU" passed as a variable argument to function "std::sprintf(char*, const char*, ...)".
2 Warning(s) detected.
below is the code that i have added:
std::set<std::string> valid;
valid.insert(string("1-1"));
could any one give me the right direction?
Below is the compilation flags:
/export/SunStudio/SUNWspro/bin/CC -c -compat=5 -features=no%altspell -features=no%export -mt +d -DTHREAD -DSOLARIS -staticlib=rwtools7 -library=rwtools7,iostream -DOWTOOLKIT_WARNING_DISABLED -Bsymbolic -PIC -g0 -DBPDEBUG
but for the sample program i am simply compiling like below:
/export/SunStudio/SUNWspro/bin/CC 0001.cc
It sounds like you have two variables in the same function that are named “valid”. Rename your new variable to
valid2or change your code to just use a single variable namedvalid, with a single declaration.You can NOT just write code like
valid.insert(string("1-1"));unless it is inside a function. In the comment below, you said it is not in a function. You need to find some constructor ofstd::set<std::string>that has the same effect as callinginsert.