|
Adding to other reply, since your class is already a list why you create a list in other forms (char *, string, vector) every time in the function call getFileNames() instead giving functioality to the class to get element of list will be useful.
class FILELIST
{
int size(); // returns number of elements in list
char *getName(int pos); // return the string corresponding to position in list.
// iterator
char *getFirst();
char *getNext();
};
or how about making use of STL itself;
typedef vector<string> FILELIST; or
typedef vector<char *> FILELIST;
or
class FILELIST: public vector<string>
modified on Friday, March 21, 2008 9:44 AM
|
|
|
|
|
Yeah, your observation is right.
Actually, my FILELIST class is substantially based on the private variable
vector<cfileinfo></cfileinfo> files, where CFILEINFO is the class I use to store info about files.
I often need to retrieve quickly a string containing all the files in the list, with a certain format,
e.g.
"c:\goofy\nc:\mickeymouse\n" and so on.
The ideas were
1) Create a FILELIST class, in which functions like char* = getFileNames() were included
2) Create public functions that wanted as argument a vector, so like char* = getFileNames(const vector<cfileinfo> files)</cfileinfo>
I didn't know what the best solution was, even because I haven't a very complete plan of my project, at the moment.
I chose the first one.
Now, if I think about the idea proposed by DadivCrow, the use of a class like in 1) would be the best, 'cuz I can overload functions. If I use main functions, I couldn't overload them like
getFileName(const vector<cfileinfo> &myFiles, char* myList) ;<br />
getFileName(const vector<cfileinfo> &myFiles, vector<string> myList) ;</string></cfileinfo></cfileinfo>
So, I think I'll use solution #1) with DavidCrow suggestion.
What do you think?
|
|
|
|
|
I'm still not satisfied.
I think that writing such a code
cout << "\n This is myList Content:" << "\n" << myList.getCharFileNames() ;
is more effective than this one
<br />
char *buff ;<br />
myList.getFilename(buff) ;<br />
cout << "\n This is myList Content:" << "\n" << buff ;
And so, I think DaveCrow's philosophy doesn't suit to me.
|
|
|
|
|
Capitanevs wrote: And so, I think DaveCrow's philosophy doesn't suit to me.
I was simply addressing your question, "As I can't overload functions with different return types (that's right?), I need to name them in different way. Do you have suggestions?" The rest is up to you.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
you can still use DavidCrows comment, if the function returns the same "char *" which is taking in.
char * FILELIST::getFilename(char *buff)
{
.....
return buff;
}
....
char *buff ;
...
cout << "\n This is myList Content:" << "\n" << myList.getFilename(buff) ;
or giving an operator overloading.
class FILELIST
{
public:
operator const char *()
{
return m_szListString;
}
private:
char m_szListString[MAX_LIST_STRING];
};
then (const char *)myList will give the string and you can directly use in cout as,
cout << "\n This is myList Content:" << "\n" << myList;
|
|
|
|
|
That could be a good solution, great!
I'll turn to more substantial problems now.
Tnx u all
|
|
|
|
|
I have this small snippet where 'a' is of short datatype.I am sending the address of short to one of the function ,another function returns the void pointer ,i want to typecast this void pointer to long but am not getting the right answer as 10 but it is giving garbage value.But if i type cast to short it gives proper value 10.For reference i am adding the code.
Plz reply me back as soon as possible.
#include<stdio.h>
void *temp;
void
call_func(void*);
void* ret_val();
int
main()
{
int a;
long b=0;
short* c;
a=10;
call_func(&a);
b=*((long*)ret_val()); ///if *((short*)ret_val)) gives proper value
c=ret_val();
printf("%ld\n",b);
printf("%d\n",*c);
return 0;
}
void
call_func(void* arg)
{
temp=arg;
}
void* ret_val()
{
return temp;
}
Thanks in Advance.
|
|
|
|
|
Of course you can't cast from void* to short* ; maybe, if you use an explicit cast, you could.
But, I question & wonder myself, why do you have to manage a void* returning function?
Did you build it by yourself or was it somewhere?
bye
M
|
|
|
|
|
First thing, please read the posting guidelines at the top of the forum: format the code with the <pre> tags, it is quite difficult to read right now.
Member 4478833 wrote: I have this small snippet where 'a' is of short datatype.
That's not what you have in your code: there it is an integer, not a short. Anyway, if it is a short then your code cannot work: basically what you are doing is converting from a pointer to short to a pointer to long. A short is 2 bytes and a long is 4 bytes. So, guess what happens ? The pointer to long will 'see' two bytes more that were not initialized by the short and those of course contains garbage.
Anyway, why are you doing stuff like that ? Playing with void pointers is something that you probably want to avoid (unless you are doing plain C progrmming).
|
|
|
|
|
hello,
I am obliged by your reply.I am aware of the situation you have mentioned ,but the problem is i have to implement the thing in the project i am working ,where the address i am sending to the void* can be of long ,char* or integer data type(so used void*),I before hand know its datatype ,if datatype is integer i typecast to long ,but i cant typecast for short.The predefined datatype mentioned in my code is either Long,Float,char*,Now i am facing problem if the address sending to the void* is short Variable ,with other datatypes i have not faced this problem...So i thought may b there is some solution for this which i am not aware of.
It will be of great help if you give any alternative you have for this.
Thanks in advance.
|
|
|
|
|
Member 4478833 wrote: c=ret_val();
Assuming you fix this syntax error, both printf() statements print 10 .
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
You really need a good tutorial (or, better, a good book) on C programming.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Hi Friends,
I have a task to write a new API such that it should commonly work for both Win XP and Linux operating systems. For example, if I am writting an API as:
MyCreateThread(...) executing it on either XP or Linux it should work.
Can anybody suggest how to wrap in such above said manner. Any relevant content ??? From where I can get?
Kindly help.
Thanks in advance
poojaaa
|
|
|
|
|
What do you want to make portable exactly ? A GUI, threading system, ... ?
Anyway, I suggest you take a look at wxWidgets[^], it is a cross-platform GUI library which has also support for threading on so on. Take a look at the features to see if it does what you are looking for.
No need to reinvent the wheel.
|
|
|
|
|
Dear Friend,
its not only about the GUIs but I need the simulation or mapping of APIs of all the services APIs supported by Win XP OS / Linux OS
Thanks in advance ... if you could help me..
poojaaa
|
|
|
|
|
|
Thank you for your reply.
I had already gone thru this article. Anything else I could know more about my query.
poojaaa
|
|
|
|
|
Ok, boys, I think it's time to give an answer to an ancestral annoying question.
How do we (we = programmers, professional or amateur) call the parts which a FQP (fully qualified path)
is made of?
I mean, if we have a DOS-like path:
c:\dir1\dir2\file.ext
what are the meaningful strings we have to name?
fileName = "file.ext" ? or
fileName = "file"
fileExtension = "ext" ? And if so, how should we call "file.ext"?
Which name is "c:\dir1\dir2" usually addressed with?
In partial paths, should I use the ending slash ("c:\dir1\") or not (c:\dir1) ?
Where can I find standard naming conventions?
And what is the best way of handling file names? Windows API, or a more convenient code
has been written, maybe here in codeproject?
Thank ya guys...
|
|
|
|
|
Do you want to write an article about?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
No...
I'm looking for answers, cause I don't have any...
Anyway, we could start a more involved discussion if there is need to shed light on this subject.
What I wonder is if there is a common convention shared by almost every programmer;
win API functions, like GetLongPathName or GetShortPathName and so on
seem to be very specific, but who really knows?
For instance, MS calls "c:\dir1\dir2\" a PathName, and "\\pcName\dir1\" as well.
But I saw someone else calling it rootPath, using the "Name" word to distinguish
between [Name of a file without extension] = FileName and [extension of a file] = FileExtension ;
in this case the [Name of a afile with extension] was called FullFileName (or FileFullName).
That's a mess!!
There must be some "sacred rules" we have to keep to.
Otherwise, we'll write them...
|
|
|
|
|
hi can anyone help me with being able to generate permutations using numbers..a c++ code. thanks
|
|
|
|
|
Does this[^] help you?
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
|
|
vikrams wrote: Now Is there any system timout I can configure for the same?
Why?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|