Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to declare a member variable in VC++ SDK

Status
Not open for further replies.

agus

Newbie level 4
Joined
Jul 20, 2005
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,386
how to add member variable to class in vc++

hai..I am beginer in programing. My question is as below;

Code:
// XXXXXView.cpp
// CXXXXXView drawing
for(i=0;i<400;i++)
   {
      for(j=0;j<400;j++){
        m=0.25*i;
        n=0.25*j;
        image[m][n]=P;
    }
 }

My question is to declare image[m][m] as a member variable.
I try to add image[m][m] as a member variable in two places,
[1]
// XXXXView.h
// Implementation
public:
image[m][m]

[2]
// XXXXView.h
// XXXXView drawing
image[m][m]

Both places give no error after compile. It is true to declare a member variable as both as above. Can someone give me a simple explanation about a global variable and also a local variable as in my example above. In the implementation of CLASS, where should I put it.

Agus
 

member variable in vc++

it's not the decalaration that's wrong, but the whole concept. I think you haven't grasp the C++ language yet. There's no support for "dynamic array" in C++, unless it's compiler specific support, that in the case of VC++, it's not there.

array must be declared with constant specifier such as this:
Code:
int image[200][200];

you can't create array with x*y size where x and y is specified dynamically at runtime.

If you want a "dynamic array", you have to use heap functions, such as malloc. Perhaps like this:
Code:
int *image;
...
image = (int*) malloc(sizeof(int) * x * y);
...
//use image here

// dont forget to free it!!

free(image);

goodluck,

Pinczakko
 

Re: How to declare a member variable in VC++ SDI

tq...I have one more basic question. The defination of CLASS in single SDI VC++. Thus the CLASS here means class.cpp,classView.cpp,classView.h,classDoc.h etc..?????

I am asking that because confusing with the implementation of CLASS in C++ source file.For example,

Code:
//Declaration of CLASS
class worker
{
  int id;
  double salary;

  void value(const int, const double);
  void show_value();
};

//Implementation of Class
void worker::value(const int id2, const double gaji2)
{
  id=id2;
  salary=salary2;
}

 .
 .
 .

void worker::show_value()

What is the CLASS defination of single SDI correspond to the above CLASS in C++ source file.

tq
 

hmmm.. lets see. Your question is blurry. But, I'll try to explain based on my understanding.

In VC++ SDI (Single Document Interface) projects, there are several predefined classes. This is the skeleton of the project, they are the Application Class (class name end up with App), View Class (class name end up with View), Document Class (class name end up with Doc), and the main window class (CMainFrame). These classes are used to represent the whole application that you're building. Data are stored in the Document Class and the "rendering/view" of the data is presented/manipulated by using the View Class, thus you can decouple the view of the data from it's "rendering/presentation".

As for adding new class, it's just as usual. Declare, implement it in separate file. Unless you are deriving from MFC classes, you won't have anything generated by VC++.

I think you should learn more about the Document/View architecture employed in MFC. Using VC++ with SDI means you are using MFC. So, you have to grasp the whole concept before messing up with it. And you should read MSDN for the class hierarchy and it's interfaces (exported functions, virtual functions and pure virtual functions/ADT)

goodluck.
 

Hay…
I have a question about studying VC++ for the purpose of calculation. I am now doing my school project using VC++. I am actually like to use VC++(Dialog Base) because it is suitable in designing a control panel of my project. But, for dialog base VC++ needs a deep understanding on Windows/ MFC structures and so on.

My question is for the purpose of calculation only (for example electronic project) do I need to study VC++ in detail and not included windows application. My purpose is just doing the algorithm and just collects a data from the output or with the output I will draw a graph.

At the same time, I am studies C# for the purpose of obtaining basic understanding of the programming language. It is because a basic knowledge in C# is needed in writing the algorithm weather in C++ or VC++. (What I am thinking!!!)

If anyone out there have an idea please give me an advice how can I tackle this matters.

Tq
:D
 

agus said:
Hay…
I have a question about studying VC++ for the purpose of calculation. I am now doing my school project using VC++. I am actually like to use VC++(Dialog Base) because it is suitable in designing a control panel of my project. But, for dialog base VC++ needs a deep understanding on Windows/ MFC structures and so on.
Anything you do with VC++ on windows DOES need a deep understanding of windows software architecture, i.e. windows_message, etc. MFC only encapsulates them. Indeed it's hard at first, but once you are accustomed to it, it'll be easy to learn others. GTK+ and XWindow uses a similar architecture. Once, I found learning GTK+ very easy to learn because of my understanding of win32API.

agus said:
My question is for the purpose of calculation only (for example electronic project) do I need to study VC++ in detail and not included windows application. My purpose is just doing the algorithm and just collects a data from the output or with the output I will draw a graph.
Depends on the interfacing with computer itself. If you are using RS232 then just use delphi or VB or other easier language/IDE. But, if you want to be able to program anything in windows then learn VC++ & Win32API. It pays off.


agus said:
At the same time, I am studies C# for the purpose of obtaining basic understanding of the programming language. It is because a basic knowledge in C# is needed in writing the algorithm weather in C++ or VC++. (What I am thinking!!!)
C# is not a widely used language in electronics/electrical engineering. I don't recommend to use it. It also has so much overhead due to its dependence on .NET library and it eats up so much resources. C++ or C is much more recommended, it depends on your need.

Perhaps, if you give some more details on your work, others will be able to help you in a better way. Also, clean-up your english ;), sometimes it's hard to dechiper what you really mean.

greetz,

Pinczakko
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top