| | |
help me in c++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2009
Posts: 13
Reputation:
Solved Threads: 0
Hello please help me
I want to declare object of base class above function main or global variable( object)
and use this object in derived class like this:
class X
{
...
}
class y : public X
{
void func();
}
void y::func()
{
a[1][0] = &c; //compiler error: a[1][0] undeclared identifier
}
////////////////////////
X* arr[8][8];
void main()
{
...
}
----------------------------
how can i do this?
because when i define like this compiler error that a[1][0] undeclared identifier
I want to declare object of base class above function main or global variable( object)
and use this object in derived class like this:
class X
{
...
}
class y : public X
{
void func();
}
void y::func()
{
a[1][0] = &c; //compiler error: a[1][0] undeclared identifier
}
////////////////////////
X* arr[8][8];
void main()
{
...
}
----------------------------
how can i do this?
because when i define like this compiler error that a[1][0] undeclared identifier
•
•
•
•
I'm guessing you actually have ... in your source instead of actual code. a and c are not anywhere to be found. Provide the full source code and we can help you. Also, use code tags and void main is now int main.
Last edited by csurfer; Jul 12th, 2009 at 9:17 am.
I Surf in "C"....
@thr:
A function in class y can work on variables declared in class y or the public variables in class x or the global variables(Usage of global variables is not recommended.).But I think you want to use the pointer to objects of class x which you have declared as
A function in class y can work on variables declared in class y or the public variables in class x or the global variables(Usage of global variables is not recommended.).But I think you want to use the pointer to objects of class x which you have declared as
X *arr[10][10] But you are using a[][] instead of arr[][] inside the function c++ Syntax (Toggle Plain Text)
void y::func() { a[1][0] = &c; //compiler error: a[1][0] undeclared identifier }
Last edited by csurfer; Jul 12th, 2009 at 9:18 am.
I Surf in "C"....
>>//compiler error: a[1][0] undeclared identifier
Another reason for that error that no one has mentioned is that the class is attempting to use that array before it has been declared. If the class is in a header file then you will also have to put the array declaration there. The easiest way to do that is to make the array a static member of class Y. If you don't want to do that then you will have to do something like this:
Another reason for that error that no one has mentioned is that the class is attempting to use that array before it has been declared. If the class is in a header file then you will also have to put the array declaration there. The easiest way to do that is to make the array a static member of class Y. If you don't want to do that then you will have to do something like this:
C++ Syntax (Toggle Plain Text)
class X { // blabla }; extern X* a[10][10]; class Y : public X { public: func() { a[1][0] = reinterpret_cast<X*>(this); } }; X* a[10][10]; int main() { }
Last edited by Ancient Dragon; Jul 12th, 2009 at 10:11 am.
•
•
Join Date: Jul 2009
Posts: 13
Reputation:
Solved Threads: 0
•
•
•
•
@thr:
A function in class y can work on variables declared in class y or the public variables in class x or the global variables(Usage of global variables is not recommended.).But I think you want to use the pointer to objects of class x which you have declared asX *arr[10][10]But you are usinga[][]instead ofarr[][]inside the function
c++ Syntax (Toggle Plain Text)
void y::func() { a[1][0] = &c; //compiler error: a[1][0] undeclared identifier }
void func()
{
arr[0][1] = &c; // compiler error to this line arr no declarade
}
•
•
•
•
excuse me i have a problem in writting above code i use arr[][] in func():
void func()
{
arr[0][1] = &c; // compiler error to this line arr no declarade
}
c++ Syntax (Toggle Plain Text)
//Definition of class X X *arr[10][10]; //Definition of class Y with public X inheritence //Function definition of Y::fun()
I Surf in "C"....
![]() |
Other Threads in the C++ Forum
- Previous Thread: C++ CLR - How to search hex in a binary file
- Next Thread: OOP in C++
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library linker list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






