473,385 Members | 1,780 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,385 software developers and data experts.

pointer to a class?

Hi

I want to declare a variable which is pointer to a class at my header.
here is my header:

base_functions.H
-----------------------------

#ifndef BASE_FUNCTIONS_H
#define BASE_FUNCTIONS_H

#ifndef BASIS
#define BASIS

#define DT 0.01

#include "weights.H"
#include <math.h>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
#include <boost/numeric/ublas/vector_proxy.hpp>


typedef struct basis_t
{
boost::numeric::ublas::matrix<float> cov;
boost::numeric::ublas::vector<float> mu;
float a;
float b;
float previous_b;
} basis;

#define ETA_C 0.1
#define ETA_M 0.1
#define INITIAL_VALUE 1.0
#define INITIAL_DELTA 1

class base_functions
{

private:

int N;
boost::numeric::ublas::matrix<float> diag
(boost::numeric::ublas::vector<float> v);
int function_num;
boost::numeric::ublas::vector<float> initial_cov;
basis* functions_vec;
C_weights* weights;

public:
base_functions(boost::numeric::ublas::vector<float >
covariance,C_weights* new_weights );
~base_functions();
int get_function_num();
bool build_new_function(float func_value, float delta);
void update(boost::numeric::ublas::vector<float> x);
float get_previous_b(int index);
float get_b(int index);
float get_max_a();
void compute_function(boost::numeric::ublas::vector<flo at> x);

};

#endif
#endif

and here is the interface of C_weight class

weights.H
-------------------

#ifndef WEIGHTS_H
#define WEIGHTS_H

#ifndef WEIGHT
#define WEIGHT

#define DT 0.01

#include "base_functions.H"

typedef struct weight_t
{
float current_value;
float prev_value;
}weight;


class C_weights
{

private:
weight* weights_vec;
public:
C_weights();
~C_weights();
float get_previous_weight(int i);
float get_current_wieght(int i);
void update_wieghts(float eta, float noise,base_functions* functions,
float delta);
bool new_weight(float func_value, float delta,int func_num);
//weight wheits_vec[0];
boost::numeric::ublas::matrix<weight> wghits_mat;
};

#endif
#endif
As you can see I tried to declare "C_weight* weights" at
base_function.H.
But when I compiled it I got the following error:

base_functions.H:66: error: ISO C++ forbids declaration of `C_weights'
with no type
base_functions.H:66: error: expected `;' before '*' token
base_functions.H:71: error: `C_weights' has not been declared
base_functions.H:71: error: ISO C++ forbids declaration of
`new_weights' with no type
I'm using Cygwin g++ 3.4.4

Thanks for your help.

Dvir

May 30 '06 #1
5 2162
* dvir:
#include "weights.H" .... base_functions.H:71: error: `C_weights' has not been declared


Declare C_weights before using it.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 30 '06 #2
You have a circular inclusion in the header files.
Don't include weight.H in base_function.H and use forward declaration
of C_weights.

BTW, In c++ you don't need to typedef the struct.

May 30 '06 #3
What do you mean by forward declaration?
Can you please write the right code line?

Thanks.
Dvir

May 30 '06 #4
Here is an example of forward declaration.

-- A.h --

class B; //forward declaration of class B.
//Note that I have not included B.h

class A
{
public:
B* pb;
};
----------- B.h -------------
#include "A.h"

class B
{
public:
A m_a; //B includes an A object as member
// hence B needs to have definition of A available to it.
};

May 30 '06 #5
"What do you mean by forward declaration? "
Forward declaratio is when you want to tell the compiler that there
is some type that you are not using but it should be award of -
class MyClass;
void f(MyClass &); // this will only work if you are not using the type
(for exmple you don't have inline function in the H file that you
implemented using this type). It is useful when you want to minimized
your include file at your H files. It will not work for member of
class/struct/unions that are not pointer/reference, function getting
this type by value (and not pointer/refernce), base classes and
enumerators/namespace
You may think of forward declaration as like the saperation between
function declation and the function implementation. Declation tell the
compiler that you have some type of function with a given name and the
implemetination is were you actualy using it. In type forward
declaration you are only tellling the compiler about at type name
Its a good practice to include as little as posible in the H file as
this is why this technic is useful. This will solve you other problem -
circular inclusion. If you are using forward declation you don't have
to include in the H file in your case.
Last but not least - never use C style typedef on struct/union/enum
since they are all types already, doing so is like typedef a class. And
even more impotant DO NOT use macro to declare const values in C++
!!!!!!!

May 30 '06 #6

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

Similar topics

2
by: lawrence | last post by:
I had some code that worked fine for several weeks, and then yesterday it stopped working. I'm not sure what I did. Nor can I make out why it isn't working. I'm running a query that should return 3...
5
by: lawrence | last post by:
I posted before, but have now narrowed my problem down to this method. At the start of the method, I test to make sure that I have a resource, a pointer to data returned from a database. This test...
2
by: Asfand Yar Qazi | last post by:
Hello. Partly for learning purposes, I have written a smart pointer class. Could you please tell me what's wrong with it? (I know there's something wrong with it, but just not what!) Note...
4
by: Carsten Spieß | last post by:
Hello all, i have a problem with a template constructor I reduced my code to the following (compiled with gcc 2.7.2) to show my problem: // a base class class Base{}; // two derived...
6
by: Itay_k | last post by:
Hello, I want a member in my class that will save pointer to pointer to System::Drawing::Image class. When I write on my class code: System::Drawing::Image **bmp; I get this error message:...
2
weaknessforcats
by: weaknessforcats | last post by:
Handle Classes Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the...
7
by: WaterWalk | last post by:
Hello. I thought I understood member function pointers, but in fact I don't. Consider the following example: class Base { public: virtual ~Base() {} }; class Derived : public Base {
5
by: Tim Frink | last post by:
Hi, I'm experimenting with function pointers and found two questions. Let's assume this code: 1 #include <iostream> 2 class A; 3 4 //////////////////////////////////////////// 5 class B
5
by: Immortal Nephi | last post by:
I would like to design an object using class. How can this class contain 10 member functions. Put 10 member functions into member function pointer array. One member function uses switch to call...
8
by: mathieu | last post by:
Hi there I have implemented a very simple smartpointer class (invasive design). And I was wondering what should be the natural API when using those in a Container. I choose to define the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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
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
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...
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
jinu1996
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 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.