![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jul 2005
Location: India
Posts: 14
Rep Power: 0
![]() |
Changed a C code to a C++ oo code, and found this error.
I have transformed a single-file C code to this single cpp file, using oop. The c program works fine. I have included the same header files. Then why am i getting this error? (I program in Linux)
the cpp file name: grp.cpp compiled this way at the command line: g++ -o grp grp.cpp I get this error message: In constructor ‘FB_Draw::FB_Draw()’: grp.cpp:26: error: ‘ioctl’ was not declared in this scope Here is s implified form of my code: //grp.cpp
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
class FB_Draw{
public:
//constructor
FB_Draw(){
//....
ioctl(..);
}
void FB_DrawPixel(..){
//...
}
//other functions
};
int main()
{
FB_Draw fb;
fb.FB_DrawPixel(10,10);
return 0;
} |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 894
Rep Power: 4
![]() |
According to the ioctl man page, you need to include <sys/ioctl.h>.
A C compiler will allow functions to be used without being declared or defined first (it makes some assumptions about the return type and parameters), but a C++ compiler won't allow that. |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jul 2005
Location: India
Posts: 14
Rep Power: 0
![]() |
Thank you, I included <sys/ioctl.h> and now the program is working fine.
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
As The-Dark said, the reason it would compile in C is that C does not require a function declaration (i.e. a prototype) to be able to call a function. At the first call of a function, if there has been no prototype, it will assume the function returns int and takes any number of arguments (and the type of any arguments passed will not be checked).
A C++ compiler will reject the same code because it enforces types of argument and return type of a function. It will therefore reject a call to a function that is called with no previous declaration. |
|
|
|
|
|
#5 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6
![]() |
did not know that!
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|