Click to See Complete Forum and Search --> : Declaration of global variables


morel
July 14th, 2007, 07:05 PM
i have creat capture.h et capture.cpp, in 1st i declared all variables us folow:



class capture
{
public:
capture(void);
~capture(void);
public:
int i;
int k;
void Ap();
};


and for capture.cpp



#include "StdAfx.h"

#include ".\capture.h"

using namespace System;

void capture::Ap() {...........................}



When i add capture.h {#include "capture.h"}in forme1.h, knowing that variable i déclared in capture.h.
In form1.h i use a variable i without declaration, there are error 'i' : undeclared identifier .

Please help me,

Thank you verry mutch

darwen
July 15th, 2007, 07:40 AM
I think you need a book on C++/CLI. Or at least one on C++.

'i' is declared as a member variable of your class 'capture'. Therefore you need an instance of your class 'capture' to access it.

Global variables in any object oriented language aren't advisable. It defeats the purpose of being object-oriented and closes the door to a lot of capabilities.

Plus having a public variable of any sort on a class isn't good practice either.

You really need to understand the fundamentals behind C++ and other object oriented languages before proceeding. And this isn't something we can tell you here... we don't have enough space !

Darwen.