|
Actually the program hangs when I try it that way. Do I have a weird VS2003 version perhaps?
Jon
|
|
|
|
|
I am using VC++ 5.0, MFC, single document. The clipboard icon on my document lights up when there is something in the clipboard. How does it know? Can I get an event message for the clipboard change?
Thanks
|
|
|
|
|
|
|
|
Hello,
I have a dialog-based MFC application, in which there is a RichEdit control, on whichever line the cursor is present inside the RichEdit control, if I press F9 key, that should show one circle with the color that VC++ uses for setting the breakpoint outside the Richedit control but on the dialog box on the same line where the cursor is present. My approach is, that if I have to work out the OnKeyDown message on the RichEdit control as a child of the dialog box, I will have to derive a class from CRichEditCtrl, which I am doing, but still not able to trap the F9 key, so that it will show the circle with that color. Please help.
Software Developer
Sanjay Khapre
|
|
|
|
|
I have been programming for years and have managed to not have to get to involved with implementing my own templates classes, so the following probably has a simple solution.
If I have declared and defined the following template class....
template <typename T> class MyClass{
public:
//.....................public members and functions
protected:
int m_int;
T m_data
};
MyClass<int> my_ints;
MyClass<char> my_chars;
The my_ints instantiation cannot access the my_char.m_int protected member variable even though that member variable is of the same type regardless of the underlying type the template encapsulates.
This should have a simple solution.
Thanks.
JK
|
|
|
|
|
Perhaps it would be clearer if you provided an example of how you are accessing my_char.m_int from my_ints.
|
|
|
|
|
OK Here goes....
Here is a useless example in real life, but this is a simplified example of where I am getting a compiler error.
template <typename T> class MyClass{
public:
//.....................public members and functions
virtual bool copy_whatever_I_can(const MyClass<T>& object);
protected:
int m_int;
T m_data
};
template <typename T> virtual bool MyClass<T>::copy_whatever_I_can(const MyClass<T>& the_char){
m_int = the_char.m_int; //all objects of MyClass have the m_int variable
return true;
}
MyClass<int> my_ints;
MyClass<char> my_chars;
my_ints.copy_whatever_I_can(my_chars); //<----this causes the cannot access protected member error
|
|
|
|
|
MyClass<int> and MyClass<char> are unrelated types. But i'm actually not sure how you can reach that protected error, since by right, the MyClass<int> class only has a function that looks like copy_whatever_I_can(const MyClass<int>& the_char) and this is not a compatible type with MyClass<char>. Is there something I'm missing? (Perhaps you are using a template function instead?)
-- modified at 14:41 Sunday 20th August, 2006
|
|
|
|
|
Actually you are correct. This was a bad example. I am trying to not copy and paste all the code becasue it is complex.
The long and short of it is, forgetting the parameter mistype in the function declaration and defintion, the question is "can templates with different basic underlying types access each others protected members assuming the protected member type is independant of the underlying base type?"
A simple analgoy is a list object.
you have the following protected members;
T* m_data;
int m_length;
All lists have the m_length variable to manage the m_data variable.
I would think there is a way to get an object of type List<int> and List<char> to access each other's m_length variable directly.
I recognize that a public function can return this but lets say for arguments sake I dont want to create the function to return length.
|
|
|
|
|
try this if you are free
template <typename t="">
class ONE
{
public:
template <typename t="">
void CopyThis(ONE<t> &s)
{
_int = s._int;
}
int _int;
T ss;
};
ONE<int> ls;
ONE<char> dir;
dir._int = 100;
ls.CopyThis(dir);
If u can Dream... U can do it
|
|
|
|
|
I think you're misunderstanding templates and member access.
A template is not a class, it's a template. One specialization of MyClass<> doesn't have any special access to the members of a different specialization. Each specialization is a different type, so MyClass<int> can't access protected members of MyClass<char> . The fact that they were both generated from the MyClass template doesn't change things.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
I was getting these errors when trying to use ios::nocreate in order to check whether a file exists prior to opening it:
void CSentenceList::readFile(char strFileToRead[MAX_FILENAME_LENGTH])
{
char strLine[MAX_SENTENCE_LENGTH + 1];
ofstream fileToRead(strFileToRead,ios::nocreate); // ios::nocreate does not seem to exist
while (!fileToRead.eof() && Size < MAX_LINES)
// Read line of text from file and update Sentences.strSentence.
{ fileToRead.getline(strLine, MAX_SENTENCE_LENGTH);
Sentences.Insert(strdup(strLine));
Size++;
}
fileToRead.close();
Error
SentenceList.cpp(23): error C2039: 'nocreate' : is not a member of 'std::basic_ios<_Elem,_Traits>'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
SentenceList.cpp(23): error C2065: 'nocreate' : undeclared identifier
SentenceList.cpp(27): error C2039: 'getline' : is not a member of 'std::basic_ofstream<_Elem,_Traits>'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
I assume that VS2003 has other functions to check whether the file exists, since these are basic C/C+ constructs.
Similarly I never reckoned why I had problems with using protected members of class templates:
SentenceList.h
class CSentenceList : public CGenericList<char*>
…
SentenceList.cpp
CSentenceList::~CSentenceList()
{Sentences.m_pFirst->data = NULL;} // this statement is incorrect but illustrates the point
Error
…SentenceList.cpp(16): error C2248: 'CGenericList<T>::m_pFirst' : cannot access protected member declared in class 'CGenericList<T>'
with
[
T=char *
]
and
[
T=char *
]
…\SentenceClass\SentenceList.cpp(16): error C2248: 'CGenericNode<T>::data' : cannot access protected member declared in class 'CGenericNode<T>'
with
[
T=char *
]
and
[
T=char *
]
GenericList.h
class CGenericList
...
protected:
int m_iCount;
CGenericNode<T> *m_pFirst;
CGenericNode<T> *m_pLast;
...
GenericNode.h
class CGenericNode
...
protected:
T data;
...
Jon
|
|
|
|
|
ios::nocreate and ios::noreplace are very pre standard C++, they were too platform specific and never made it into the new standard. You will find them in the old <fstream.h> headers as opposed to your <fstream> header. Your out of luck, try validating the file yourself.
fstream fs(“fname”, ios_base::in);// attempt open for read
if (!fs)
{
// file doesn't exist; don't create a new one
}
else //ok, file exists. close and reopen in write mode
{
fs.close();
fs.open(“fname”, ios_base::out); // reopen for write
}
-- modified at 13:59 Sunday 20th August, 2006
|
|
|
|
|
What's wrong with ios::nocreate? I am getting these errors in VS2003:
SentenceList.cpp(23): error C2039: 'nocreate' : is not a member of 'std::basic_ios<_Elem,_Traits>'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
SentenceList.cpp(23): error C2065: 'nocreate' : undeclared identifier
Code:
void CSentenceList::readFile(char strFileToRead[MAX_FILENAME_LENGTH])
{
char strLine[MAX_SENTENCE_LENGTH + 1];
fstream fileToRead(strFileToRead,ios::nocreate);
while (!fileToRead.eof() && Size < MAX_LINES)
// Read line of text from file and update Sentences.strSentence.
{ fileToRead.getline(strLine, MAX_SENTENCE_LENGTH);
Sentences.Insert(strdup(strLine));
Size++;
}
fileToRead.close();
}
Jon
|
|
|
|
|
Are you dynamically linking to the header file?
|
|
|
|
|
I have included fstream...
#include <fstream>
Jon
|
|
|
|
|
try:
#include<fstream.h>
I have had ios::nocreate work with the .h include statement, but I haven't had anything work with just the fstream include statement.
|
|
|
|
|
#include <iostream>
#include <conio.h>
#include <iomanip>
using namespace std;
ostream& curren(ostream &s, int fieldSize)
{
cout << "$";
cout.setf(ios.fixed | ios::showpoint);
cout.precision(2);
cout.width(fieldSize);
return s;
}
// was this deprecated??
omanip (int) currency (int fieldSize);
{
return omanip<int>(curren,fieldSize);
}
void main ()
{
double someMoney = 13.5678;
cout<<currency(7)<<someMoney<<endl;
}
Jon
|
|
|
|
|
|
Actually it seems Microsoft left it out from omanip that comes bundled with VS2003, however it seems to be available on Borland (which I don't have).
Thanks for your help.
Jon
|
|
|
|
|
Help me to figure out, how can i control windows explorer with my program ?. For example i want to make program if i click button "back" in my program, it command windows explorer to back, if i click button "up", it command windows explorer to going up from current directory. is this possible to make ???? please help me
Sory about my english, like you guess english not my mother language
|
|
|
|
|
You might want to start of by using a spy utility like SPY++ to find out what commands and such are sent when buttons are pressed. If you can find that out it should be a simple task as sending the window a message )
|
|
|
|
|
i create a thread and got the Handle.
how can i get the following information of the thread?
1. is the thread object signaled? when can it be signaled?
2. is the thread suspended? it is easy but how to get the suspend count?
3. has the thread terminated? what happens to the thread object if the thread funtion quits? reset to NULL?
i looked up the google but could not get clear answer, wish you guys here can help me out, thanks alot!
|
|
|
|