Hi
I want to use a set of N classes.
I have a class called "C_weights" which compute and update a set of
weights for function aprroximation.
Now, the user should determine how much functions are needed.
Therefore, If the user needs N functions, I need to call the class
"C_weights" N times.
How should I do this?
I thought maybe to build an array of C_weights, but I'm not sure if its
the right solution.
Thanks, for your help.
Dvir 3 1627 sc*****@gmail.c om wrote: I want to use a set of N classes.
Do you mean /n/ classes or /n/ instances of the class /C_weights/?
I have a class called "C_weights" which compute and update a set of weights for function aprroximation. Now, the user should determine how much functions are needed. Therefore, If the user needs N functions, I need to call the class "C_weights" N times. How should I do this? I thought maybe to build an array of C_weights, but I'm not sure if its the right solution.
That really depends on what you mean by "call the class". Do you mean
you will need to construct /n/ instances of the class, depending on the
user's input? Or do you mean that you will have to invoke a given method
of that class /n/ times? If the former, a dynamically-allocated array or
a vector (preferred) should do just fine. E.g.:
cout << "How many functions? ";
int n;
cin >> n;
vector<C_weight > weightCalculato rs(n);
There you have a collection of /n/ C_weight objects. Is that what you
are looking for?
Regards,
--
Ney André de Mello Zunino
> Do you mean /n/ classes or /n/ instances of the class /C_weights/?
well I dont really understand the differnce between those two options,
so I'll try to describe what I want to do.
This is the interface of the 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_we ight(int i);
float get_current_wie ght(int i);
void update_wieghts( float eta, float noise,base_func tions* functions,
float delta);
bool new_weight(floa t func_value, float delta,int func_num);
//weight wheits_vec[0];
boost::numeric: :ublas::matrix< weight> wghits_mat;
};
#endif
#endif
this class contain all the characteristics of the set of weights which
define a function.
I want to use N functions.
Each function uses different set of weights.
How should I do it?
Can I have a vector of C_weights?
What is the differnce between vector and array?
Thanks.
Dvir
"dvir" <sc*****@gmail. com> wrote in message
news:11******** **************@ g10g2000cwb.goo glegroups.com.. . Do you mean /n/ classes or /n/ instances of the class /C_weights/? well I dont really understand the differnce between those two options, so I'll try to describe what I want to do. This is the interface of the 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;
I suggest you change this to
std::vector<wei ght> weights_vec;
It will make everything easier.
public: C_weights(); ~C_weights();
// if you need this you also need a copy constructor and assignment
operator. But if you use std::vector you don't need this.
float get_previous_we ight(int i); float get_current_wie ght(int i); void update_wieghts( float eta, float noise,base_func tions* functions, float delta); bool new_weight(floa t func_value, float delta,int func_num); //weight wheits_vec[0]; boost::numeric: :ublas::matrix< weight> wghits_mat;
Public data is not usually a good idea. Is this really what you mean?
};
#endif #endif
this class contain all the characteristics of the set of weights which define a function. I want to use N functions. Each function uses different set of weights. How should I do it?
See suggestions above. However, if you really just want N sets of weights
you might consider
typedef std::vector<wei ght> t_weight_vec;
This construction corresponds very closely to your problem statement: you
want "N functions" which means "N sets of weights". You can write
convenience functions rather than class member functions to do work on this
type:
// not a member function; just a function -- note first argument
void update_wieghts( t_weight_vec &wv, float eta, float noise, base_functions
*functions, float delta);
Can I have a vector of C_weights?
Sure. std::vector<C_w eights> whatever;
Or:
typedef std::vector<t_w eight_vec> t_weight_mat;
What is the differnce between vector and array?
The names are historical accidents. std::vector can be used for a
geometrical vector but is often used with non-numerical types. On the other
hand std::valarray, which is intended for numerical types and therefore is
much more likely to be a geometrical vector obviously has the wrong name.
The C language construct int x[5]; is usually called an array also.
I suggest you study up on std::vector. It works fine with numerical and
non-numerical types and is easy to use and generally efficient. Thanks. Dvir
You're welcome.
Cy This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bob Rock |
last post by:
Hello,
in the last few days I've made my first few attempts at creating mixed C++
managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is
visible in those assemblies from a managed point-of-view I've noticed that:
1) for each managed and unmanaged C function (not C++ classes) I get a
public managed static method...
|
by: Jack |
last post by:
Hello
I have a library of calculationally intensive classes that is used both by a
GUI based authoring application and by a simpler non-interactive rendering
application. Both of these applications need to serialise the classes
to/from the same files but only the GUI app needs the full range of class
methods.
Now, the rendering app needs...
|
by: Aguilar, James |
last post by:
I know that one can define an essentially unlimited number of classes in a
file. And one can declare just as many in a header file. However, the
question I have is, should I?
Suppose that, to use the common example, I have a situation where I am
implementing many types of Shapes. My current way of thinking is, well,
since they are all...
|
by: Langy |
last post by:
Hello
I'm fairly new to C++ but have programmed several other languages and
found most of c++ fairly easy (so far!).
I've come to a tutorial on classes, could someone please tell me why
you would need to use a class?
Perhaps you could also give an example on when it might be used rather
than an alternative method.
|
by: john townsley |
last post by:
do people prefer to design classes for the particular job or for a rangle of
tasks they might encounter now and in the future.
i am doing some simple win32 apps and picking classes is simple, but
understanding others peoples logic isnt (that doesnt mean they are wrong).
i prefer designing classes for the currect job and making tangible...
| |
by: joye |
last post by:
Hello,
My question is how to use C# to call the existing libraries containing
unmanaged C++ classes directly, but not use C# or managed C++ wrappers
unmanaged C++ classes?
Does anyone know how to do that?
Thanks.
Tsung-Yu
|
by: Edward Diener |
last post by:
Is the packing alignment of __nogc classes stored as part of the assembly ?
I think it must as the compiler, when referencing the assembly, could not
know how the original data is packed otherwise. Yet, in my understanding,
attributes are only __gc and __value class specific and do not apply to
__nogc classes. Is this correct ? If so, how is...
|
by: ivan.leben |
last post by:
I want to write a Mesh class using half-edges. This class uses three
other classes: Vertex, HalfEdge and Face. These classes should be
linked properly in the process of building up the mesh by calling Mesh
class functions. Let's say they point to each other like this:
class Vertex {
HalfEdge *edge;
};
class HalfEdge {
Vertex* vert;
|
by: ivan.leben |
last post by:
I am writing this in a new thread to alert that I found a solution to
the problem mentioned here:
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/7970afaa089fd5b8
and to avoid this topic getting lost before people interested in the
problem notice it.
The important tricks to the solution are two:
1) make the custom classes...
|
by: Amu |
last post by:
i have a dll ( template class) ready which is written in
VC++6. But presently i need to inherit its classes into my new C#.net
project.so if there is some better solution with u then please give me
the solution.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |