How to use a class multiple times?
I need a little syntax help please :)
Code:
some_class some_function
(QString some_string
) {some_class string_collection;
if (some_string.isEmpty()) {
more_strings = new some_class("Warning", "Error", "FooBar");
}
else {
more_strings = new some_class("Warning1", "Error1", "FooBar1");
}
return more_strings; }
I can't compile that ... where is my mistake?
Re: How to use a class multiple times?
Crystal ball does not work. Show the real code and messages from the compiler.
Re: How to use a class multiple times?
Code:
some_class
* some_function
(QString some_string
) {//some_class string_collection;
some_class * more_strings = 0;
if (some_string.isEmpty()) {
more_strings = new some_class("Warning", "Error", "FooBar");
}
else {
more_strings = new some_class("Warning1", "Error1", "FooBar1");
}
return more_strings; }
Re: How to use a class multiple times?
@Santosh Reddy:
I am a little bit confused with
Code:
some_class
* some_function
(QString some_string
)
in your example.
@Lesilok: The whole code I had in the beginning. Compiler says: "Fehler:C2664: 'MultiReturn::MultiReturn(const MultiReturn &)': converting parameter 1 from 'MultiReturn *' to 'const MultiReturn &' not possible"
Code:
MultiReturn read_in
(QString incoming_string
) {
MultiReturn string_collection;
if (incoming_string.isEmpty()) {
string_collection = new MultiReturn("Warning", "Error", "Mind");
}
else {
string_collection = new MultiReturn("Warning1", "Error1", "Mind1");
}
return string_collection; }
When I do it like this, it compiles, but crashes instantly (thats what I made from Santosh Reddy's advice):
Code:
MultiReturn read_in
(QString incoming_string
) {
MultiReturn *string_collection = 0;
if (incoming_string.isEmpty()) {
string_collection = new MultiReturn("Warning", "Error", "Mind");
}
else {
string_collection = new MultiReturn("Warning1", "Error1", "Mind1");
}
return *string_collection; }
Re: How to use a class multiple times?
Discard the "new" keyword from your original code.
Re: How to use a class multiple times?
Thanks wysota, that did the trick!