here is the code:
---
#ifndef XFILE_A2_H
#define XFILE_A2_H
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
namespace xf{
class Xfile{
public:
void compress();// throw (runtime_error);
void stats();// throw (runtime_error);
private:
Xfile(string = "mydata", int = 10, int = 10); //constructor
typedef char* Xstr;
Xstr* storage_; //an array of array to store the data
int size_; //lines array contains
int length_; //length for each line
}
}
#endif
----
GCC gives me this error:
xfile_a2.h:23: error: parse error before `}' token
xfile_a2.h: In function `int xf::main()':
xfile_a2.h:17: error: `xf::Xfile::Xfile(std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int, int)' is private
anyone knows why(maybe a newbie question)? Thanks. 7 1271
Daqian Yang wrote: here is the code: --- #ifndef XFILE_A2_H #define XFILE_A2_H
#include <iostream> #include <fstream> #include <string> using namespace std;
namespace xf{ class Xfile{
public: void compress();// throw (runtime_error); void stats();// throw (runtime_error);
private: Xfile(string = "mydata", int = 10, int = 10); //constructor typedef char* Xstr; Xstr* storage_; //an array of array to store the data int size_; //lines array contains int length_; //length for each line }
};
} #endif
----
GCC gives me this error: xfile_a2.h:23: error: parse error before `}' token
Fixed by adding the semi-colon.
xfile_a2.h: In function `int xf::main()': xfile_a2.h:17: error: `xf::Xfile::Xfile(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, int)' is private
I would need to see xf::main to tell the exact problem. However the only
constructor for Xfile is private and therefore you will struggle to
create an Xfile object. The only why an Xfile object could be created is
by: a static Xfile method and there isn't one; a friend class and once
again there isn't one; or by a method of Xfile but due to the previous
facts there will not be a way to call a method of Xfile (chicken and egg
problem).
Michael Mellor
After I modified the program like this it has no compiling error:
--
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
namespace xf{
class Xfile{
public:
void compress();// throw (runtime_error);
void stats();// throw (runtime_error);
private:
Xfile(string = "mydata", int = 10, int = 10); //constructor
typedef char* Xstr;
Xstr* storage_; //an array of array to store the data
int size_; //lines array contains
int length_; //length for each line
};
};
---
anyone can tell me why?
Daqian Yang wrote: After I modified the program like this it has no compiling error:
-- #include <iostream> #include <fstream> #include <string> using namespace std;
namespace xf{ class Xfile{
public: void compress();// throw (runtime_error); void stats();// throw (runtime_error);
private: Xfile(string = "mydata", int = 10, int = 10); //constructor typedef char* Xstr; Xstr* storage_; //an array of array to store the data int size_; //lines array contains int length_; //length for each line }; }; ---
anyone can tell me why?
In simple terms you can write:
class a {
public:
int f ( );
} an_object;
void func() {
an_object.f()
}
which defines a class of type 'a' and create an object 'an_object' of
type 'a'. So if you don't want to also create an object of type 'a' when
defining it you need:
class a {
public:
int f ( );
};
Dont't put semi colons after namespaces as it is standard although g++
(and I guess many other compilers) allow it:
namespace xf{
class Xfile{
......
}; // ; does go here
} // No ; here
Michael Mellor
Daqian Yang wrote: After I modified the program like this it has no compiling error:
-- #include <iostream> #include <fstream> #include <string> using namespace std;
namespace xf{ class Xfile{
public: void compress();// throw (runtime_error); void stats();// throw (runtime_error);
private: Xfile(string = "mydata", int = 10, int = 10); //constructor typedef char* Xstr; Xstr* storage_; //an array of array to store the data int size_; //lines array contains int length_; //length for each line }; }; ---
anyone can tell me why?
A semicolon is required after a class declaration:
class Xfile
{
....
}; // Notice the semicolon
You left the semicolon out in your original version and the
compiler complained. A semicolon is NOT required when closing
a namespace:
namespace xf
{
....
} // No semicolon needed here, though you use one
Daqian Yang wrote: After I modified the program like this it has no compiling error:
-- #include <iostream> #include <fstream> #include <string> using namespace std;
namespace xf{ class Xfile{
public: void compress();// throw (runtime_error); void stats();// throw (runtime_error);
private: Xfile(string = "mydata", int = 10, int = 10); //constructor typedef char* Xstr; Xstr* storage_; //an array of array to store the data int size_; //lines array contains int length_; //length for each line }; }; ---
anyone can tell me why?
because you need a semicolon after the class definition. BTW, you don't
need one after the namespace definition.
"Daqian Yang" <05*****@acadiau.ca> wrote in message news:<bv**********@poseidon.acadiau.ca>... After I modified the program like this it has no compiling error:
-- #include <iostream> #include <fstream> #include <string> using namespace std;
namespace xf{ class Xfile{
public: void compress();// throw (runtime_error); void stats();// throw (runtime_error);
private: Xfile(string = "mydata", int = 10, int = 10); //constructor typedef char* Xstr; Xstr* storage_; //an array of array to store the data int size_; //lines array contains int length_; //length for each line }; }; ---
anyone can tell me why?
When you declare a class you MUST end it with a ;
class Foo
{
..whatever in here..
}; // This is important to have!
I believe this is the case with namespaces also. Remove the ; on the
last } and see if you get your error back (as you should)
Kiel W. wrote: When you declare a class you MUST end it with a ;
class Foo { ..whatever in here.. }; // This is important to have!
I believe this is the case with namespaces also. Remove the ; on the last } and see if you get your error back (as you should)
No, namespaces do not require the semicolon. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Brandon J. Van Every |
last post by:
What's better about Ruby than Python? I'm sure there's something. What is
it?
This is not a troll. I'm language shopping and I want people's answers. I
don't know beans about Ruby or have...
|
by: Moon |
last post by:
Seems I still haven't got the hang of all those window generating code
in Javascript. I've got a page with about 15 photo thumbnails. When you
click on a thumbnail a new window pops up which shows...
|
by: Steven T. Hatton |
last post by:
This is something I've been looking at because it is central to a currently
broken part of the KDevelop new application wizard. I'm not complaining
about it being broken, It's a CVS images. ...
|
by: FrankStallone |
last post by:
I am just getting started in XML and I made my first xml, dtd and xslt
file and XML spy said they were all valid and they worked.
This was the xslt doc that worked.
<?xml version="1.0"...
|
by: ship |
last post by:
Hi
We need some advice: We are thinking of upgrading our Access database
from Access 2000 to Access 2004.
How stable is MS Office 2003? (particularly Access 2003).
We are just a small...
|
by: priya |
last post by:
hi.i made mistake while copying my code sorry friends.This is the one i
tried .i got o/p for dynamic rows how should i h'v to incorporate
"onChange"event in "setAttribute". following code is not...
|
by: Xah Lee |
last post by:
in March, i posted a essay “What is Expressiveness in a Computer
Language”, archived at:
http://xahlee.org/perl-python/what_is_expresiveness.html
I was informed then that there is a academic...
|
by: axlq |
last post by:
I'm trying to design my style sheets such that my pages have
similar-looking fonts different platforms (Linux, Mac, Adobe,
X-Windows, MS Windows, etc).
The problem is, a font on one platform...
|
by: Cromulent |
last post by:
On 2008-07-06 21:09:55 +0100, Joe Wright <joewwright@comcast.netsaid:
Err, no not really as that has nothing to do with stock market prices :).
--
"I disapprove of what you say, but I'll defend...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |