View Full Version : How to use a class multiple times?
xtlc
8th August 2013, 15:56
I need a little syntax help please :)
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?
Lesiok
8th August 2013, 16:09
Crystal ball does not work. Show the real code and messages from the compiler.
Santosh Reddy
8th August 2013, 16:10
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; }
xtlc
8th August 2013, 16:28
@Santosh Reddy:
I am a little bit confused with
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"
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):
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; }
wysota
8th August 2013, 16:34
Discard the "new" keyword from your original code.
xtlc
8th August 2013, 16:48
Thanks wysota, that did the trick!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.