The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 vector<string> compile error
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

ThomasR

Germany
6 Posts

Posted - 12/16/2013 :  05:28:58 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello, could some please hint me on my mistake?
I want to get a string array as return of a function. It does not compile with the error "line(0). no matching constructor" (I translated that error into english). But the other 2 functions for comparison work. If I comment the line below //(3), it compiles.

#include <Origin.h>

int test(){
	int bla=10;
	return bla;	
}

string test_string(){
	string testname = "blub";
	return testname;
}

vector<string> test_vectorstring(){
	vector<string> testvec = {
		"blub",
		"hello",
		"grrrrrr"
	};
	return testvec;
}


int getColIndex()
{
        //(1)
	int testint = test();

        //(2)	
	string testname = test_string();	
	
        //(3)
	vector<string> testvec = test_vectorstring();

	return 0;
}

rlewis

Canada
253 Posts

Posted - 12/16/2013 :  06:06:33 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I don't think there is an OC string constructor that accepts a string value ... The following seems to work ..


   vector<string> testvec;
   testvec= test_vectorstring(); 
Go to Top of Page

ThomasR

Germany
6 Posts

Posted - 12/16/2013 :  06:12:55 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by rlewis

I don't think there is an OC string constructor that accepts a string value ... The following seems to work ..


You are right. Thank you very much, I did not consider this.
Now I am just wondering why someone wouldn't implement a constructor analog to the others. This makes no sense but perhaps my view is too limited.
Go to Top of Page

Castiel

343 Posts

Posted - 12/16/2013 :  08:27:53 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Instead of returning an array, I prefer to pass by reference and return its size:

int foo(vector<string> & v)
{
    // ....
    return v.GetSize();
}


妾+   午旦  妹罕妾  妾伊    用仇  妾/     岫ㄞ
 妾京用 仍巨  件 侈   件戶' 甘岫平   /欠  白岫妹
   併             艮          岫  奈 白   岫
                              岫
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000