Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 15th, 2006, 1:59 AM   #1
rup
Newbie
 
Join Date: Jul 2005
Location: India
Posts: 14
Rep Power: 0 rup is on a distinguished road
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;
}
rup is offline   Reply With Quote
Old Mar 15th, 2006, 2:47 AM   #2
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 894
Rep Power: 4 The Dark is on a distinguished road
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.
The Dark is offline   Reply With Quote
Old Mar 15th, 2006, 10:55 AM   #3
rup
Newbie
 
Join Date: Jul 2005
Location: India
Posts: 14
Rep Power: 0 rup is on a distinguished road
Thank you, I included <sys/ioctl.h> and now the program is working fine.
rup is offline   Reply With Quote
Old Mar 16th, 2006, 6:38 AM   #4
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5 grumpy will become famous soon enough
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.
grumpy is offline   Reply With Quote
Old Mar 18th, 2006, 1:56 AM   #5
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6 bl00dninja is on a distinguished road
Lightbulb

did not know that!
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:42 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC