LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-08-2009, 04:50 PM   #1
flanders
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Rep: Reputation: 0
Aggregate Error in c++ using g++ compiler


I keep getting an error in my code. Normally I'd be able to work it out, but the error is apart of some code that our teacher provided for us. I went over to his office, but he left for the day already.

The exact error is:

"error: aggregate 'std::stringstream strstr' has incomplete type and cannot be defined"

Here is the function that brings up the error:

string StatVect09 :: toString(int numPerLine, string sep) const
{
stringstream strstr;
string str;
string retString;
strstr.clear();
strstr << data [0];
strstr >> str;
retString += str;
for (int i = 1; i < VECT_SIZE; ++i ) {
retString += sep;
retString += " ";
if ((numPerLine > 0 ) && (i % numPerLine == 0 )) retString += "\n";
strstr.clear();
strstr << data [i];
strstr >> str;
retString += str;
}
return retString;
}

I can provide more info if needed, but any help at all is extremely appreciated.
 
Old 04-08-2009, 05:20 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
The immediate problem is that it needs a #include <sstream>

However, the code you've posted has a rather large number of problems. First, it is a misuse of stringstream, and should really create an ostringstream, push stuff into it, then return the result of str(). Second, the string argument should be declared const reference, it's an idiom for complex types to avoid copy construction. It should also assert() that the number of items in the vector is greater than 0 and that numPerLine is greater than or equal to 0.

But the most important question is.. Why can't you use std::vector?
 
Old 04-08-2009, 06:40 PM   #3
flanders
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Thank you, that solved the problem.

As to answer your questions, I don't know. This entire block of code I copied was provided entirely by our teacher and I didn't modify it at all which was why I was really confused why it was giving me problems.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
checking for C compiler default output... configure: error: C compiler cannot create fiorejm Linux - Software 6 11-12-2009 12:35 PM
How can I make my aggregator actually *aggregate*? Chriswaterguy Linux - Software 2 04-16-2008 12:48 AM
GCC compiler giving syntax error before 'double' error dragonmint Programming 2 06-02-2007 02:07 PM
c++ initialization lists (error, non aggregate type) Que? byteframe Programming 2 12-15-2005 06:58 PM
"Not an aggregate type"- Error in g++ ashwinipahuja Programming 2 04-26-2004 06:14 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration