i created a function which u send a string, and it tokenizes according to spaces, so i send it a string for it to return me a string array, but on the declaration of the function it says
error C2470: 'splitter' : looks like a function definition, but there is no parameter list; skipping apparent body
and
error C2092: 'splitter' array element type cannot be function
and my header is
string splitter[](string line)
i read the other day that the return value could be anythin as long as its one object ,int, string, array, as long as its one object, so what am i doing wrong?
thanks in advance
11 12913 Savage 1,764
Recognized Expert Top Contributor
i created a function which u send a string, and it tokenizes according to spaces, so i send it a string for it to return me a string array, but on the declaration of the function it says
error C2470: 'splitter' : looks like a function definition, but there is no parameter list; skipping apparent body
and
error C2092: 'splitter' array element type cannot be function
and my header is
string splitter[](string line)
i read the other day that the return value could be anythin as long as its one object ,int, string, array, as long as its one object, so what am i doing wrong?
thanks in advance
it's because of spliter[],you cannot have array element type as a return value.Change it to *spliter and it will work.
Savage
thanks a lot :D it worked
it all worked, function wise, but when i call it, i get this error
warning C4172: returning address of local variable or temporary
do u happpen to know why that is?? thanks a lot again
well i figured i had to have it declared withthe public functions, which i did, but now i get a new error,
1>retrieveGeoCm dCmd.obj : error LNK2019: unresolved external symbol "class std::basic_stri ng<char,struct std::char_trait s<char>,class std::allocator< char> > __cdecl splitter(class std::basic_stri ng<char,struct std::char_trait s<char>,class std::allocator< char> >)" (?splitter@@YA? AV?$basic_strin g@DU?$char_trai ts@D@std@@V?$al locator@D@2@@st d@@V12@@Z) referenced in function "public: virtual class MStatus __thiscall retrieveGeoCmd: :doIt(class MArgList const &)" (?doIt@retrieve GeoCmd@@UAE?AVM Status@@ABVMArg List@@@Z)
yes this is one error :S
help??
Savage 1,764
Recognized Expert Top Contributor
thanks a lot :D it worked
it all worked, function wise, but when i call it, i get this error
warning C4172: returning address of local variable or temporary
do u happpen to know why that is?? thanks a lot again
Can I take a look on your spliter function?
Savage
there u go -
string *splitter(string line)
-
{
-
int strBegin=0, strLocale=0, i=1, strCount=0, j, strLngth ;
-
string str, thread[100];
-
str = line;
-
-
while(strLocale != string::npos)
-
{
-
strLocale = str.find(" ",strBegin);
-
strLngth = strLocale-strBegin;
-
thread[i] = str.substr(strBegin,strLngth);
-
strBegin = strLocale + 1;
-
strCount++;
-
i++;
-
};
-
-
for (j = 1; j <= strCount; j++)
-
cout << thread[j] << " ";
-
return thread;
-
-
}
Savage 1,764
Recognized Expert Top Contributor
there u go - string *splitter(string line)
-
{
-
int strBegin=0, strLocale=0, i=1, strCount=0, j, strLngth ;
-
string str, thread[100];
-
str = line;
-
-
while(strLocale != string::npos)
-
{
-
strLocale = str.find(" ",strBegin);
-
strLngth = strLocale-strBegin;
-
thread[i] = str.substr(strBegin,strLngth);
-
strBegin = strLocale + 1;
-
strCount++;
-
i++;
-
};
-
-
for (j = 1; j <= strCount; j++)
-
cout << thread[j] << " ";
-
return thread;
}
You are returning thread which is local to the function.If this function is part of larger class,you might wont to make thread a private/protected member of the class,second option is to reform your function.
void splitter(string line,string *thread) and then use function argument to retrieve splinted string.
Savage
im sorry for being such a noob :S but i really am workin my ass off to understand everything, i read and worked most of the deitel n deitel book, but its like all the resources guide me to do the simple stuff, and if i want guides to do sth complicated, they always assume im an advanced user of c++ (which i dont blame them 4) knowing that im working on the maya api. not to bore u any more, ill go on with my problem
first of all i tried declaring it in the main class as private, and i still got that error, then i went on, kept it as private and i got this error
1>d:\maya work\api projects (c++)\retrieveg eocmd\retrieveg eocmd\retrieveg eocmdcmd.cpp(23 0) : error C2440: '=' : cannot convert from 'std::basic_str ing<_Elem,_Trai ts,_Ax>' to 'std::string *'
if i try to remove the declaration and only use the second solution ill get an undeclared identifier error,
thanks again m8!
Savage 1,764
Recognized Expert Top Contributor
im sorry for being such a noob :S but i really am workin my ass off to understand everything, i read and worked most of the deitel n deitel book, but its like all the resources guide me to do the simple stuff, and if i want guides to do sth complicated, they always assume im an advanced user of c++ (which i dont blame them 4) knowing that im working on the maya api. not to bore u any more, ill go on with my problem
first of all i tried declaring it in the main class as private, and i still got that error, then i went on, kept it as private and i got this error
1>d:\maya work\api projects (c++)\retrieveg eocmd\retrieveg eocmd\retrieveg eocmdcmd.cpp(23 0) : error C2440: '=' : cannot convert from 'std::basic_str ing<_Elem,_Trai ts,_Ax>' to 'std::string *'
if i try to remove the declaration and only use the second solution ill get an undeclared identifier error,
thanks again m8!
Can you show me that line of code?
Savage
Savage 1,764
Recognized Expert Top Contributor
there u go
string *splitter(strin g line)
{
int strBegin=0, strLocale=0, i=1, strCount=0, j, strLngth ;
string str, thread[100];
str = line;
while(strLocale != string::npos)
{
strLocale = str.find(" ",strBegin) ;
strLngth = strLocale-strBegin;
thread[i] = str.substr(strB egin,strLngth);
strBegin = strLocale + 1;
strCount++;
i++;
};
for (j = 1; j <= strCount; j++)
cout << thread[j] << " ";
return thread;
}
Also first index in a array is 0 not 1
Savage
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Obscurr |
last post by:
i've got an array created in php that I want to send over to a javascript function.
onclick = "return sjekk(<?echo $names; ?> )"
in my "sjekk" function, when I try to print an alert :
function sjekk(navn)
{
alert(navn); // or alert(navn)
return(false);
|
by: Foxy Kav |
last post by:
Hi everyone, im a first year UNI student doing a programming subject
and im stuck on how to get rid of my global variables, char
stringarray and char emptystring. I was wondering if
anyone could show me a example of how to do this. I was told to pass
the arrays from function to function, but i do not know how ....
Thanxs if you can help.
My code (First two functions only - there's more):
|
by: Woody Splawn |
last post by:
How would I pass an array back to a sub routine from a function? That is, I
have a function that looks like this
Public Function arrayTest() As Array
Dim states() As String = { _
"AZ", "CA", "WA" _
}
Return states
End Function
|
by: John |
last post by:
Hi
I need to return an array of string in my own split function (access 97). I
have defined the function as below but I get err on 'As String()'. What can
I do to make the function return an array of strings?
Public Function Split(ByVal strIn As String, Optional strDelimiter As String
= " ") As String()
Thanks
|
by: _Mario.lat |
last post by:
Hallo,
I have a little question:
In the function session_set_save_handler I can pass the name of function
which deal with session.
In Xoops code I see the use of this function like that:
session_set_save_handler(array(&$sess_handler, 'open'),
array(&$sess_handler, 'close'), array(&$sess_handler, 'read'),
array(&$sess_handler, 'write'), array(&$sess_handler, 'destroy'),
array(&$sess_handler, 'gc'));
| |
by: Christian Maier |
last post by:
Hi
After surfing a while I have still trouble with this array thing. I
have the following function and recive a Segmentation fault, how must
I code this right??
Thanks
Christian Maier
|
by: Raj |
last post by:
I need a VB function to return array of collections like
Private Type Employee
empname as string
address as string
salary as integer
deptno as integer
End Type
dim employees() as Employee
|
by: Andrew Morton |
last post by:
Is it possible to have two function declarations which take the same
parameters but return different types depending on how the function is used?
function f(x) as string
' return a string
end function
function f(x) as string()
' return an array of strings
end function
|
by: David Mark |
last post by:
I've got a collection of functions that accept a function or object
(paired with a method name) as a callback.
For the longest time I have relied on this test.
(typeof cb == 'function')
This should work as well, but I am not sure how well it degrades in
older browsers. I think there are issues with functions created in
another context (eg frame) as well.
|
by: =?Utf-8?B?RGFya21hbg==?= |
last post by:
Hi,
I am wondering how you multi-dimension an array function?
My declared function looks like this:
Public Function GetCustomerList(ByVal Val1 As String, ByVal Val2 As Long,
ByVal Val3 As String) As String()
Previously I dimensioned a single dimension Array to the size I wanted and
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |