473,811 Members | 2,971 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Class Usage

I have defined the following class:
//-----------------------------------------------------------------
class LogFunctions // Log/Audit File class
{
public:
LogFunctions::L ogFunctions(cha r *fileName); // constructor
LogFunctions::~ LogFunctions(); // destructor

void LogFunctions::o penLog(char *fileName); // open Log file
void LogFunctions::p utLog(char *line); // write->Log/Audit file
void LogFunctions::s canLog(); // scan Log/Audit file
void LogFunctions::c loseLog(); // close current log/audit file
static int listFile(char *fileName); // lists named file

private:
static void cursor(char row, char col);
static void initScr(void);
static char *fileReadRecord (long);
static void parseStr(char *str); // parse string from file buffer

typedef unsigned long ULONG;
};
//-----------------------------------------------------------------
and I am having difficulty using this class as an object pointer. I
need to use it several times (with different files) throughout the
execution of my application. That is, I want to have several files
concurrently opened, writing, being scanned, etc. within the same
program. Thus, I thought would do the following:
//-----------------------------------------------------------------
LogFunctions *l_c = NULL;
....
LogFunctions *l_c = new LogFunctions("t estfile.log");
....
l_c->putLog("Some textual data");
l_c->scanLog();
etc.
....
l_c->closeLog();
delete(l_c);
//-----------------------------------------------------------------
This sort of code generates all sorts of compile errors (which don't
help me understand what I did wrong), and I know I've badly confused the
concepts of class definition and instantiation.. .8<}}
So, if my explanation of my intent makes sense, I'd appreciate some
guidance as to how actually implement this logic... TIA
Nov 9 '07 #1
4 1407
Michael R. Copeland wrote:
I have defined the following class:
//-----------------------------------------------------------------
class LogFunctions // Log/Audit File class
{
public:
LogFunctions::L ogFunctions(cha r *fileName); // constructor
Should be

LogFunctions(ch ar const*);
LogFunctions::~ LogFunctions(); // destructor
Should be

~LogFunctions() ;

If you don't see it yet, there is no need to prepend the names of the
member function declarations with the class name and '::' _inside_ the
class definition.
>
void LogFunctions::o penLog(char *fileName); // open Log file
Again, a pointer to _const_ char.
void LogFunctions::p utLog(char *line); // write->Log/Audit file
Again, a pointer to _const_ char.
void LogFunctions::s canLog(); // scan Log/Audit file
What does it mean to "scan" it?
void LogFunctions::c loseLog(); // close current log/audit file
static int listFile(char *fileName); // lists named file
Again, a pointer to _const_ char.
>
private:
static void cursor(char row, char col);
static void initScr(void);
If there are no arguments, it's better to have empty parentheses, as
in

static void initScr();
static char *fileReadRecord (long);
static void parseStr(char *str); // parse string from file buffer
Again, a pointer to _const_ char.
>
typedef unsigned long ULONG;
I suppose there is some use for this...
};
//-----------------------------------------------------------------
and I am having difficulty using this class as an object pointer. I
need to use it several times (with different files) throughout the
execution of my application. That is, I want to have several files
concurrently opened, writing, being scanned, etc. within the same
program. Thus, I thought would do the following:
//-----------------------------------------------------------------
LogFunctions *l_c = NULL;
Why do youi need to declare it here? And *where* is that?
...
LogFunctions *l_c = new LogFunctions("t estfile.log");
You seem to be declaring *another* object with the name 'l_c' here.
Do you really need two of them?
...
l_c->putLog("Some textual data");
l_c->scanLog();
etc.
...
l_c->closeLog();
delete(l_c);
Parentheses? Why?
//-----------------------------------------------------------------
This sort of code generates all sorts of compile errors (which don't
help me understand what I did wrong), and I know I've badly confused
the concepts of class definition and instantiation.. .8<}}
*What* sorts of compile errors? I cannot get them since the code you
posted is not real -- it's an exerpt.
So, if my explanation of my intent makes sense, I'd appreciate some
guidance as to how actually implement this logic... TIA
Have you tried looking on the web? If you haven't, do, and look for
'log4cpp' project. There is no need to reinvent the wheel. Just find
what you need and use it.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 9 '07 #2
and I am having difficulty using this class as an object pointer. I
need to use it several times (with different files) throughout the
execution of my application. That is, I want to have several files
concurrently opened, writing, being scanned, etc. within the same
program. Thus, I thought would do the following:
//-----------------------------------------------------------------
LogFunctions *l_c = NULL;
Why do you need to declare it here? And *where* is that?

It's in the main line of the program: when I'm opening data files,
etc.
...
LogFunctions *l_c = new LogFunctions("t estfile.log");
You seem to be declaring *another* object with the name 'l_c' here.
Do you really need two of them?

Ahhh, no. This is part of my confusion about declaring classes and
instantiating objects of them for use.
...
l_c->putLog("Some textual data");
l_c->scanLog();
etc.
...
l_c->closeLog();
delete(l_c);
Parentheses? Why?

Just my lack of knowledge/understanding of class usage... 8<{{
//-----------------------------------------------------------------
This sort of code generates all sorts of compile errors (which don't
help me understand what I did wrong), and I know I've badly confused
the concepts of class definition and instantiation.. .8<}}
*What* sorts of compile errors? I cannot get them since the code you
posted is not real -- it's an exerpt.

Well, it wraps my VS6.0 compiler to its limit (102 errors), and there
are so many I didn't see how I could enumerate them. They start with
the
LogFunctions *l_c = new LogFunctions("t estfile.log");
line.
So, if my explanation of my intent makes sense, I'd appreciate some
guidance as to how actually implement this logic... TIA
Have you tried looking on the web? If you haven't, do, and look for
'log4cpp' project. There is no need to reinvent the wheel. Just find
what you need and use it.

I'll do that now. I was trying to establish some "class" knowledge,
as I thought this was a rather simple application for my usage. Oh
well...
Nov 9 '07 #3
Michael R. Copeland wrote:
>//-----------------------------------------------------------------
This sort of code generates all sorts of compile errors (which
don't help me understand what I did wrong), and I know I've badly
confused the concepts of class definition and instantiation.. .8<}}

*What* sorts of compile errors? I cannot get them since the code you
posted is not real -- it's an exerpt.

Well, it wraps my VS6.0 compiler to its limit (102 errors), and
there are so many I didn't see how I could enumerate them. They
start with the
>LogFunctions *l_c = new LogFunctions("t estfile.log");
line.
You might be better off if you get yourself a more up-to-date compiler.
VS6 is very old and just bad. If you can't buy 2005, get the Express
Edition, it's free.
> So, if my explanation of my intent makes sense, I'd appreciate some
guidance as to how actually implement this logic... TIA

Have you tried looking on the web? If you haven't, do, and look for
'log4cpp' project. There is no need to reinvent the wheel. Just find
what you need and use it.

I'll do that now. I was trying to establish some "class" knowledge,
as I thought this was a rather simple application for my usage. Oh
well...
Your time is better spent on developing something new, something that
is original, something that is needed for your future work. Don't waste
it rewriting something freely available for reuse.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 9 '07 #4
"Michael R. Copeland" <mr*****@cox.ne twrote in message
news:MP******** *************** *@news.cox.net. ..
I have defined the following class:
//-----------------------------------------------------------------
class LogFunctions // Log/Audit File class
{
public:
LogFunctions::L ogFunctions(cha r *fileName); // constructor
LogFunctions::~ LogFunctions(); // destructor

void LogFunctions::o penLog(char *fileName); // open Log file
void LogFunctions::p utLog(char *line); // write->Log/Audit file
void LogFunctions::s canLog(); // scan Log/Audit file
void LogFunctions::c loseLog(); // close current log/audit file
static int listFile(char *fileName); // lists named file

private:
static void cursor(char row, char col);
static void initScr(void);
static char *fileReadRecord (long);
static void parseStr(char *str); // parse string from file buffer

typedef unsigned long ULONG;
};
//-----------------------------------------------------------------
and I am having difficulty using this class as an object pointer. I
need to use it several times (with different files) throughout the
execution of my application. That is, I want to have several files
concurrently opened, writing, being scanned, etc. within the same
program. Thus, I thought would do the following:
//-----------------------------------------------------------------
LogFunctions *l_c = NULL;
LogFunctions *l_c = new LogFunctions("t estfile.log");

should allow it to compile as long as you have the rest of the class done
(actual code).

But please, read Victors post, there is a lot that should be cleaned up
(like constant correctness).

You could also do:
LogFunctions *l_c = NULL;
l_c = new LogFunctions("t estfile.log");

But there is no reason to assign it to NULL when on the next line you're
going to give it a value anyway. Best to just put on one line.
...
LogFunctions *l_c = new LogFunctions("t estfile.log");
...
l_c->putLog("Some textual data");
l_c->scanLog();
etc.
...
l_c->closeLog();
delete(l_c);
//-----------------------------------------------------------------
This sort of code generates all sorts of compile errors (which don't
help me understand what I did wrong), and I know I've badly confused the
concepts of class definition and instantiation.. .8<}}
So, if my explanation of my intent makes sense, I'd appreciate some
guidance as to how actually implement this logic... TIA

Nov 10 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
10851
by: Fu Bo Xia | last post by:
the java.lang.Object.forName method takes a java class name and returns a Class object associated with that class. eg. Class myClass = Object.forName("java.lang.String"); by if i only know the absolute file name of a .class file eg. C:\myJava\myApp.java, then how do i translate this file name to a java class name the Object.forName method would accept has it's parameter? thanks,
10
1881
by: george young | last post by:
I had developed the habit of using the neat python form: if someinstance: someinstance.memb() because it seems cleaner than "if someinstance is not None". {please no flames about "is not None" vs. "!= None" ...} This seemed like a good idea at the time :(). Twice, recently, however, as my app grew, I thought, hmm... it would make things clearer if I gave
6
2320
by: Peter Kleiweg | last post by:
I'm still new to Python. All my experience with OO programming is in a distant past with C++. Now I have written my first class in Python. The class behaves exactly as I want, but I would like to get comments about coding style. I'm especially unsure about how a class should be documented, what to put in, and where. When to use double quotes, and when single. For instance, the doc string at the top must be in double quotes, or else the...
166
8700
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
2
1630
by: Fish | last post by:
I have been researching the correct way to organize my solution so that it makes best use of VB.NET inherent ability to manage resources such as objects. My solution contains 2 projects and the main problem is that the mem usage continues to grow until the Service stops responding. I have received advice to: "create those objects at a class level; instantiate them when the service starts, and dispose of them when the service ends. Then...
4
1680
by: Mark | last post by:
I want to create a collection class that will be strongly typed (store a specific object type), be keyed with a case insensitive string, and be able to access objects stored by index, or sequentially (in the order stored) via "For Each". I know I could code this from scratch - or derived from a number of framework classes, but I'm not sure of the pros/cons of various possibilities. I'd like to use some of the new Generics - they are...
7
2118
by: WXS | last post by:
Vote for this idea if you like it here: http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=5fee280d-085e-4fe2-af35-254fbbe96ee9 ----------------------------------------------------------------------------- This is a consortium of ideas from another thread on topic ----------------------------------------------------------------------------- One of the big issues of organizing items within a class, is there are many...
25
2155
by: David Sanders | last post by:
Hi, As part of a simulation program, I have several different model classes, ModelAA, ModelBB, etc., which are all derived from the class BasicModel by inheritance. model to use, for example if the parameter model_name is "aa", then choose ModelAA. Currently I do this as follows:
4
1904
by: Devon Null | last post by:
I have been exploring the concept of abstract classes and I was curious - If I do not define a base class as abstract, will it be instantiated (hope that is the right word) when a derived class is created? if ( answer == false ) { Would the idea of an abstract class simply be used to enforce integrity of the classes by disallowing the abstract class to be instantiated, or are there other purposes for it? }
30
2477
by: Alf P. Steinbach | last post by:
I once suggested in that SomeOne Else(TM) should propose a string value class that accepted literals and char pointers and so on, with possible custom deleter, and in case of literal strings just carrying the original pointer. In other words, for the simplest usage code: * no overhead (just carrying a pointer or two), and * no possibility of exceptions (for that case).
0
9730
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10392
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10403
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10136
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5555
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4341
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3868
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.