473,403 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Class members

Jim
I have made a class which includes some of the methods in the class
declaration, which is in the header;

slice.h
class Slice{
private:
float cdelt1,cdelt2;
float crval1,crval2;
float crpix1,crpix2;
int crval3;
string filename;
long ax1,ax2;
valarray<floatcontents;
void readData();
public:
Slice(string fnm,int i);
float getCDelt1(){ return cdelt1;}
float getCDelt2(){ return cdelt2;}
float getCRPix1(){ return crpix1;}
float getCRPix2(){ return crpix2;}
float getCRVal1(){ return crval2;}
float getCRVal2(){ return crval2;}
int getCRVal3(){ return crval3;}
long getax1(){ return ax1;}
long getax2(){ return ax2;}
void copyData(valarray<float& data, int i);
};

As these have already been declared in the class declaration I thought
they would have been included as class members but I get an error in
assemble when I try to compile the file using this class.
assemble.cpp:49: error: 'class std::slice' has no member named
'getCDelt1'
assemble.cpp:50: error: 'class std::slice' has no member named
'getCDelt2'
assemble.cpp:51: error: 'class std::slice' has no member named
'getCRVal1'
assemble.cpp:52: error: 'class std::slice' has no member named
'getCRVal2'
assemble.cpp:53: error: 'class std::slice' has no member named
'getCRPix1'
assemble.cpp:54: error: 'class std::slice' has no member named
'getCRPix2'
assemble.cpp:55: error: 'class std::slice' has no member named
'getax1'
assemble.cpp:56: error: 'class std::slice' has no member named
'getax2'
assemble.cpp:61: error: 'class std::slice' has no member named
'copyData'
I tried re-writing the names in the class declaration as e.g
Slice::copyData, but that didn't work. How should I be doing this?
Putting the class def in the header and commenting it out of the .cpp
has been the only way I can get multiline programs to compile. Also,
does anyone know an efficient C++ method to go from strings to floats
or doubles? At the moment I convert to c_str and use atof.

Thanks!

Feb 16 '07 #1
4 1525
On 16 feb, 13:13, "Jim" <j...@astro.livjm.ac.ukwrote:
I have made a class which includes some of the methods in the class
declaration, which is in the header;

slice.h
class Slice{
private:
float cdelt1,cdelt2;
float crval1,crval2;
float crpix1,crpix2;
int crval3;
string filename;
long ax1,ax2;
valarray<floatcontents;
void readData();
public:
Slice(string fnm,int i);
float getCDelt1(){ return cdelt1;}
float getCDelt2(){ return cdelt2;}
float getCRPix1(){ return crpix1;}
float getCRPix2(){ return crpix2;}
float getCRVal1(){ return crval2;}
float getCRVal2(){ return crval2;}
int getCRVal3(){ return crval3;}
long getax1(){ return ax1;}
long getax2(){ return ax2;}
void copyData(valarray<float& data, int i);

};

As these have already been declared in the class declaration I thought
they would have been included as class members but I get an error in
assemble when I try to compile the file using this class.
assemble.cpp:49: error: 'class std::slice' has no member named
'getCDelt1'
assemble.cpp:50: error: 'class std::slice' has no member named
'getCDelt2'
assemble.cpp:51: error: 'class std::slice' has no member named
'getCRVal1'
assemble.cpp:52: error: 'class std::slice' has no member named
'getCRVal2'
assemble.cpp:53: error: 'class std::slice' has no member named
'getCRPix1'
assemble.cpp:54: error: 'class std::slice' has no member named
'getCRPix2'
assemble.cpp:55: error: 'class std::slice' has no member named
'getax1'
assemble.cpp:56: error: 'class std::slice' has no member named
'getax2'
assemble.cpp:61: error: 'class std::slice' has no member named
'copyData'

I tried re-writing the names in the class declaration as e.g
Slice::copyData, but that didn't work. How should I be doing this?
Putting the class def in the header and commenting it out of the .cpp
has been the only way I can get multiline programs to compile. Also,
does anyone know an efficient C++ method to go from strings to floats
or doubles? At the moment I convert to c_str and use atof.

Thanks!
it says std::
So your standard library already has a class named slice ;-) Try
something like ::slice in your assemble.cpp and see if that makes it
compile.

Feb 16 '07 #2
On 16 feb, 13:13, "Jim" <j...@astro.livjm.ac.ukwrote:
I have made a class which includes some of the methods in the class
declaration, which is in the header;

slice.h
class Slice{
private:
float cdelt1,cdelt2;
float crval1,crval2;
float crpix1,crpix2;
int crval3;
string filename;
long ax1,ax2;
valarray<floatcontents;
void readData();
public:
Slice(string fnm,int i);
float getCDelt1(){ return cdelt1;}
float getCDelt2(){ return cdelt2;}
float getCRPix1(){ return crpix1;}
float getCRPix2(){ return crpix2;}
float getCRVal1(){ return crval2;}
float getCRVal2(){ return crval2;}
int getCRVal3(){ return crval3;}
long getax1(){ return ax1;}
long getax2(){ return ax2;}
void copyData(valarray<float& data, int i);

};

As these have already been declared in the class declaration I thought
they would have been included as class members but I get an error in
assemble when I try to compile the file using this class.
assemble.cpp:49: error: 'class std::slice' has no member named
'getCDelt1'
assemble.cpp:50: error: 'class std::slice' has no member named
'getCDelt2'
assemble.cpp:51: error: 'class std::slice' has no member named
'getCRVal1'
assemble.cpp:52: error: 'class std::slice' has no member named
'getCRVal2'
assemble.cpp:53: error: 'class std::slice' has no member named
'getCRPix1'
assemble.cpp:54: error: 'class std::slice' has no member named
'getCRPix2'
assemble.cpp:55: error: 'class std::slice' has no member named
'getax1'
assemble.cpp:56: error: 'class std::slice' has no member named
'getax2'
assemble.cpp:61: error: 'class std::slice' has no member named
'copyData'

I tried re-writing the names in the class declaration as e.g
Slice::copyData, but that didn't work. How should I be doing this?
Putting the class def in the header and commenting it out of the .cpp
has been the only way I can get multiline programs to compile. Also,
does anyone know an efficient C++ method to go from strings to floats
or doubles? At the moment I convert to c_str and use atof.

Thanks!

btw, for converting you could try http://www.boost.org/libs/conversion/lexical_cast.htm

Feb 16 '07 #3
On Feb 16, 1:13 pm, "Jim" <j...@astro.livjm.ac.ukwrote:
I have made a class which includes some of the methods in the class
declaration, which is in the header;

slice.h
class Slice{
assemble.cpp:49: error: 'class std::slice' has no member named
'getCDelt1'
Notice the difference in case of the first letter in the name of the
class, your class is named Slice but you are trying to use a class
called slice. Looks like you have 'using namespace std;' somewhere,
which is a bad habit.

--
Erik Wikström

Feb 16 '07 #4
Jim <ja@astro.livjm.ac.ukwrote:
I have made a class which includes some of the methods in the class
declaration, which is in the header;

slice.h
class Slice{
private:
float cdelt1,cdelt2;
float crval1,crval2;
float crpix1,crpix2;
int crval3;
string filename;
long ax1,ax2;
valarray<floatcontents;
void readData();
public:
Slice(string fnm,int i);
float getCDelt1(){ return cdelt1;}
float getCDelt2(){ return cdelt2;}
float getCRPix1(){ return crpix1;}
float getCRPix2(){ return crpix2;}
float getCRVal1(){ return crval2;}
float getCRVal2(){ return crval2;}
int getCRVal3(){ return crval3;}
long getax1(){ return ax1;}
long getax2(){ return ax2;}
void copyData(valarray<float& data, int i);
};

As these have already been declared in the class declaration I thought
they would have been included as class members but I get an error in
assemble when I try to compile the file using this class.
assemble.cpp:49: error: 'class std::slice' has no member named
'getCDelt1'
[snip similar errors]

Note that C++ is case sensitive, so "slice" is different from "Slice".
Also, I see that you are using std::valarray, which has its own concept
of slice, so you must make sure that your Slice and the std::slice do
not conflict.
I tried re-writing the names in the class declaration as e.g
Slice::copyData, but that didn't work. How should I be doing this?
Putting the class def in the header and commenting it out of the .cpp
has been the only way I can get multiline programs to compile.
Try doing it like this:

// slice.h
#ifndef SLICE_H
#define SLICE_H

class Slice {
private:
float cdelt1, cdelt2;
float crval1, crval2;
// the rest are left as an exercise to the reader
void readData();
public:
// as Erik mentioned, you probably have a 'using namespace std;' in
// your header, which is not recommended; instead you should fully
// qualify the names in the header.
// Using it in your .cpp file is OK though.
Slice(std::string fnm, int i);
// any reason you're not passing by reference to const, like
// Slice(const std::string& fnm, int i);
// ?
};

#endif
// slice.cpp
#include "slice.h"

Slice::Slice(std::string fnm, int i)
: filename(fnm) // these are just a guess based on the names and
, crval3(i) // types of the variables
{
// any other initialization
}

void Slice::readData()
{
// implement the readData() function here
}
Also,
does anyone know an efficient C++ method to go from strings to floats
or doubles? At the moment I convert to c_str and use atof.
Well, some people have debated the efficiency of this method, but you
shouldn't really worry about that until you've determined that it is
indeed an issue. See this FAQ (and the surrounding ones too):

http://www.parashift.com/c++-faq-lit....html#faq-39.2

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Feb 16 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Carlos Ribeiro | last post by:
I thought about this problem over the weekend, after long hours of hacking some metaclasses to allow me to express some real case data structures as Python classes. I think that this is something...
8
by: CoolPint | last post by:
I read in books that nested class cannot access private members of nesting class and vice versa unless they are made friends. Somehow, my compiler is letting my nested class member functions access...
3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
5
by: kuvpatel | last post by:
Hi I want to refer a class called LogEvent, and use one of its methods called WriteMessage without actually having to create an instance of Logevent. I have tried using the word sealed with...
5
by: Chris | last post by:
Hi, I don't get the difference between a struct and a class ! ok, I know that a struct is a value type, the other a reference type, I understand the technical differences between both, but...
1
by: D Witherspoon | last post by:
Coming up with a scenario here. For example there is the standard .NET MailMessage class. I am creating a project (let's call it CommonBase) that has the following 2 classes ...
9
by: olanglois | last post by:
Hi, I am not sure if I have found a compiler bug (I am using VC++.NET2003) or if this is the correct behavior defined by the language but I am sure someone can clear up my confusion. Suppose the...
14
by: lovecreatesbea... | last post by:
Could you tell me how many class members the C++ language synthesizes for a class type? Which members in a class aren't derived from parent classes? I have read the book The C++ Programming...
10
by: Joel | last post by:
Is it true that if we don't specify a default constructor for our class, then the C# compiler provides us with its own that zeroes (or assigns default values) to the data members? I wrote a...
8
by: crjjrc | last post by:
Hi, I've got a base class and some derived classes that look something like this: class Base { public: int getType() { return type; } private: static const int type = 0; };
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.