Hello, I have a function that returns a map <int, struct> . However, the compiler complains. my function declaration in my class is as follows: map <int, struct> test_class:: test function(). In my function,
I define a struct Rows. and my map is map<int,Rows> Options
. .. . return Options; compiler doesn't like that.
There are messages: 1) one that is related to map <int, struct> : "Expected either a definition or a tag name" 2)one at the return statement : "no suitable user -defined conversion from "..." exists.
Any ideas please? It should be something simple that I am missing in my code. thanks
Pavan ------------------------------------------------------------------------------ Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and much more. Get web development skills now with LearnDevNow - 350+ hours of step-by-step video tutorials by Microsoft MVPs and experts. SALE $99.99 this month only -- learn more at: http://p.sf.net/sfu/learnmore_122812 _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Define Rows outside of the function. If your struct is defined inside the function, then it cannot be made visible outside that function. In particular, it cannot be used as the return type of the function, which should be map<int,Rows> in any case.
Date: Fri, 11 Jan 2013 10:05:58 -0800 From: [hidden email] To: [hidden email] Subject: [Quantlib-users] returning a map <int, stuct> from my member function in my class Hello, I have a function that returns a map <int, struct> . However, the compiler complains. my function declaration in my class is as follows: map <int, struct> test_class:: test function(). In my function,
I define a struct Rows. and my map is map<int,Rows> Options
. .. . return Options; compiler doesn't like that.
There are messages: 1) one that is related to map <int, struct> : "Expected either a definition or a tag name" 2)one at the return statement : "no suitable user -defined conversion from "..." exists.
Any ideas please? It should be something simple that I am missing in my code. thanks
Pavan ------------------------------------------------------------------------------ Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and much more. Get web development skills now with LearnDevNow - 350+ hours of step-by-step video tutorials by Microsoft MVPs and experts. SALE $99.99 this month only -- learn more at: http://p.sf.net/sfu/learnmore_122812 _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users ------------------------------------------------------------------------------ Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and much more. Get web development skills now with LearnDevNow - 350+ hours of step-by-step video tutorials by Microsoft MVPs and experts. SALE $99.99 this month only -- learn more at: http://p.sf.net/sfu/learnmore_122812 _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
I believe it worked when I defined the structure in the same header file as my class but outside the function definition. In other words, as peter suggested, define the structure in my .h file.
I think it worked because the compiler doesn't give any errors. However, when I tried to call this function from my int main (),
it doesn't work. Can you see anything wrong with this function definition? Am I parsing a string date correctly by using the DateParser::parseISO(vec[4]) ? vec[4] is a string as you can see below but in my struct Rows, it expects a Date.
map<int,test_load::Rows> test_load::Load_Ports_Struct() {
string data ("testfile.csv"); string line; ifstream Ports(data.c_str()); typedef tokenizer <escaped_list_separator <char> > Tokenizer;
vector<string>vec; int key;
//the actual data structure map<int,test_load::Rows> Options; //////////////
while (getline(Ports,line)) {
Tokenizer tok(line); vec.assign(tok.begin(),tok.end()); key=atoi(vec[0].c_str()); //tradeid in every row is the key Rows each_option ={ vec[1],vec[2], vec[3], QuantLib::DateParser::parseISO(vec[4]), vec[5],atof(vec[6].c_str()),atof(vec[7].c_str()),vec[8],atof(vec[9].c_str()),
atof(vec[10].c_str()),atof(vec[11].c_str()),atof(vec[12].c_str()), QuantLib::DateParser::parseISO(vec[13]) };
//put the sample data into the map Options[key]=each_option;
} cout << Options[6003].Notional <<endl;
Ports.close(); return Options;
thanks a lot Pavan
On Fri, Jan 11, 2013 at 12:15 PM, Jan Ladislav Dussek <[hidden email]> wrote:
------------------------------------------------------------------------------ Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and much more. Get web development skills now with LearnDevNow - 350+ hours of step-by-step video tutorials by Microsoft MVPs and experts. SALE $99.99 this month only -- learn more at: http://p.sf.net/sfu/learnmore_122812 _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Kyle, thanks for the code The compiler still errors out.
And I think I know why now. The tradeDate and expDate in my csv file is of the format "10/6/2010" . The compiler errors out and goes directly to dataparsers.cpp file. A window pops up that says "Unhandled exception at 0x75bbc41f in TestingQuantLib.exe: Microsoft C++ exception: QuantLib::Error at memory location 0x002ffb2c ."
Do you think this is the problem? Perhaps, "10/6/2010" is invalid format. btw, 10 = month, 6 = day, and 2010 = year .
All the dates in my file are in the format "10/6/2010" .
Thanks Pavan On Fri, Jan 11, 2013 at 9:35 PM, Kyle Schlansker <[hidden email]> wrote:
------------------------------------------------------------------------------ Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS, MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft MVPs and experts. SALE $99.99 this month only -- learn more at: http://p.sf.net/sfu/learnmore_122412 _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |