LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 12-15-2005, 03:11 PM   #1
byteframe
Member
 
Registered: Oct 2005
Distribution: Slackware
Posts: 62

Rep: Reputation: 15
c++ initialization lists (error, non aggregate type) Que?


Here's my code.
Code:
#ifndef TEXTFILE_H
#    define TEXTFILE_H

#include <string>

class TextBuffer {
    protected:
        std::string lastFile;
        std::string buffer;
        int charCnt;
        int wordCnt;
        
    public:
        TextBuffer();
        TextBuffer(std::string);
        
        std::string getLastFile() const { return lastFile; }        
        std::string getBuffer() const { return buffer; }
        int getCharCnt() const { return charCnt; }
        int getWordCnt() const { return wordCnt; }

        void setBuffer(std::string toSet, bool willAppend);
        
        bool OpenFile(std::string in_filename, bool willAppend);
        void SaveFile(std::string in_filename);
};

#endif
Code:
#include "TextBuffer.h"
#include <fstream>

TextBuffer::TextBuffer(): 
    buffer(""),
    lastFile(""),
    charCnt(0),
    wordCnt(0) {                  
}

TextBuffer::TextBuffer(std::string in_lastFile): 
    buffer(""),                                         
    lastFile(in_lastFile),
    charCnt(0),
    wordCnt(0) {
}
... other functions not added...
and heres my test.cpp client program...

Code:
#include "TextBuffer.h"

#include <iostream>

using namespace std;

int main() {
    TextBuffer myTextBuffer();
    rotatedOne.OpenFile("../../two.txt", false);
    cout << rotatedOne.getBuffer();
    cout << "\n\nchars" << rotatedOne.getCharCnt() << endl << endl;
    system("pause");
}
My entire project is much bigger than this, but I'm having trouble with using member initialization lists. This program doesnt compile and I get...

Code:
../test.cpp: In function `int main()':
../test.cpp:9: request for member `OpenFile' in `myTextBuffer()', which is of 
   non-aggregate type `TextBuffer ()()'
../test.cpp:10: request for member `getBuffer' in `myTextBuffer()', which is of 
   non-aggregate type `TextBuffer ()()'
../test.cpp:11: request for member `getCharCnt' in `myTextBuffer()', which is 
   of non-aggregate type `TextBuffer ()()'
yet if I base a string value to myTextBuffer. ie myTextBuffer("Untitled-1"); The program works fine and compiles fine. What am I doing wrong?

Please help thank you.
 
Old 12-15-2005, 05:02 PM   #2
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
Here's the diff:
Code:
int main() {
-    TextBuffer myTextBuffer();
+    TextBuffer myTextBuffer;
}
 
Old 12-15-2005, 06:58 PM   #3
byteframe
Member
 
Registered: Oct 2005
Distribution: Slackware
Posts: 62

Original Poster
Rep: Reputation: 15
Oh my god I'm a fucking idiot.
 
  


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
xemacs: initialization/error laurentwahl Linux - Software 4 10-02-2005 05:51 AM
ldirectord initialization error depdiver Linux - Software 0 05-12-2005 04:38 PM
static initialization error wasp Programming 2 03-15-2005 05:11 AM
Hi dakensta- one more problem- "Not an aggregate type" ashwinipahuja Programming 3 04-30-2004 06:42 AM
"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 08:04 PM.

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