•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 423,539 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,266 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 729 | Replies: 2
![]() |
•
•
Join Date: Feb 2008
Location: Canada
Posts: 20
Reputation:
Rep Power: 1
Solved Threads: 1
Hello, I am a fairly inexperienced programmer, and I am confusing myself.
I want to have a member function or a different class return an array of structures. I've read that I have to do this by reference, but I can seem to get it right. Can someone help?
The header file has the line:
The structure is declared(?) as follows:
This is the member function of RoboDOM, which will be called by the class named compare. I am using Qt4, and I think the xml traversing is alright, if not I can probably figure that part out myself.
And at last, it is here called by compare. I assume this is where I'm going wrong, or maybe in what I am returning. I think I have a lot of trouble with the syntax of pointers because maybe I don't understand them very well.
Eitherway, the error I am currently getting is:
Thank you very much in advanced!
I want to have a member function or a different class return an array of structures. I've read that I have to do this by reference, but I can seem to get it right. Can someone help?
The header file has the line:
static struct Comm* listCommands(QString directory, QString docName); \\comm is the name of the structure
The structure is declared(?) as follows:
struct Comm //command structure
{
QString cLabel;
};struct Comm* RoboDOM::listCommands(QString directory, QString docName)
{
QStringList transList;
QDomDocument doc = openDoc(directory, docName);
QDomElement docElem = doc.documentElement();
QDomNode n = docElem.firstChild();
QDomNodeList tagList = doc.elementsByTagName("commands");
n = tagList.item(0);
QDomNodeList commandList = n.childNodes;
Comm *commands[50]; //Make an array of structs
for(int i = 0; i<commandList.count();i++)
{
n = commandList.item(i);
e = n.toElement();
QStringList newone;
newone << "Command"<<i;
Comm newone.join(" ") =
{
nameCode(e.tagName())
}
commands[i] =newone.join(" ");
}
return commands;
}Comm *listofcommands[50] = RoboDOM::listCommands(directory, protocol1); QString Listy = listofcommands[0].cLabel; type1->setText(Listy);
Eitherway, the error I am currently getting is:
compare.cpp:98: error: invalid initializer compare.cpp:99: error: `cLabel' has not been declared compare.cpp:99: error: request for member of non-aggregate type before ';' token
Thank you very much in advanced!
Comm *listofcommands[50] = RoboDOM::listCommands(directory, protocol1);QString Listy = listofcommands[0]->cLabel; tuxation.com - Linux articles, tutorials, and discussions
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: RemoveAll Function (for an Array)
- Next Thread: Purpose of Pointers?



Linear Mode