|
Microsoft Visual C++ 6.0 with SP5. I said it compiled, but I did not run it.
Hosam Aly Mahmoud
|
|
|
|
|
Hi all,
Can someone help me fix and understand why this doesn't work. I keep getting an error saying:
error C2079: 'Node<T>::data' uses undefined class 'T' with[ T=T]
HELP PLEASE...this is driving me crazy?
|
|
|
|
|
well.....since you don't give me that much information to work with, i'm thinking that you defined a template class like so:
template <class t=""> (or <typename t="">)
class CTempl
{
CTempl<t>();
};
and implemented your methods like this:
CTempl<t>::CTempl<t>(){}
This result in a similair error as you described and it means you haven't included the following statement, above the method impl.:
template <class t="">
CTempl<t>::CTempl<t>(){}
Is this what you mean, or did i type all this for sh*t?
|
|
|
|
|
The file I added, was actually present in the project workspace before, under a different name. Following some changes I made to the file, I gave it a new name, and then deleted the old version from the workspace, followed by adding the newly named one to the same workspace (using Project->Add To Project->Files). Other changes made, were to the "#include" statement in the program, and the directory where the program and its files are located.
Did a "Rebuild All" and the compiler came back saying it couldn't open the newly named file.
Any idea why the compiler is not seeing the newly added file in "Dev Studio"??
Thanks!
William
Fortes in fide et opere!
|
|
|
|
|
Switch to the file list and right click on the file to get its properties. Is the file really
where VC thinks it is?
Also, changing files can quite often confuse the poor IDE, so close VC, and delete the projects NCB file.
Run VC again, and do a "Rebuild All". It should be okay now.
Iain.
|
|
|
|
|
Thanks for replying.
Tried your suggestion. It didn't help. The same error keeps getting cited.
Also ran a little experiment. I removed ALL the C++ files the project uses (everyone of them), then did a "Rebuild all" and the same single error returned about not being able to open that newly named file I've been talking about (even though the physical file is no longer in the directory with the ".exe" file. Interestingly, the compiler made no mention about the other files that were removed also. It just said it couldn't find that one file. (Yes, I did delete the ".ncb" file followed by a "Rebuild all".
Dev Studio is a strange creature after all, and it stands to fact I've much to learn about its idiosyncrasies.
William
Fortes in fide et opere!
|
|
|
|
|
By implication, I presume the file you are talking about is not a C/CPP/H file.
It is a dependency of other files in your project (e.g. resource). Do you custom-build
it into an intermediate file which is included in your project?
I would open the project settings and check for mention in your file in any of the
command line parameter bits on the bottom right. This may give you a clue.
Iain.
|
|
|
|
|
The file in question is a C++ file, in that it has ".h" as it's extension.
In reality, it is a MACRO file that I have all sorts of macros in, which as a matter of routine I '#include' it in nearly all my programs. Recently however, I began doing some house cleaning on it, hence the reason for renaming it, and it's that new name that the program is saying it cannot find to open the file (even though the file is physically present in the same directory as the ".exe" file). The same renamed file is also present in the project workspace which when I click on it, I see all the new changes I made to it.
I cannot understand why the compiler is saying it is unable to find the file.
Thanks for your continued suggestions.
William
Fortes in fide et opere!
|
|
|
|
|
by default the file is expected to be in the same directory as the project (.dsp) file, otherwise you need to do one of the following;
a) mangle the include statement in your files (e.g. #include "..\common\abc.h", or
b) add the path via Project -> Settings -> C++ -> Preprocessor -> Additional Include directories.
nb
|
|
|
|
|
Thanks for replying.
I think some confusion is beginning to emerge between the use of the word "folder" and "directory" (and maybe I hold some blame for that).
I use the word "folder" to mean, "a place in a directory where one or more files are located."
"Directory," I use, to denote a path from the drive letter where a certain "folder" is located.
Some of the answers I get (well-intentioned as they are), are beginning to reflect this confusion, which if I can help clear things up, "The newly named file, resides in the same folder (in the same directory) as the ".dsp" file."
Unlike C++ where the programmer can do some rather clever things and the compiler will go along with his code, "Dev Studio" is not very clever. Simply substituting a file by removing the old one from the workspace and "adding in" a new one to the same workspace, is too complicated a task for it to understand and do.
What I simply did, was made some changes to a file, then renamed the file (no change of folder or directory done). Next, I went into the project workspace, deleted the old file and "added" the newly named file (which is residing in the same folder and directory as the old file) into the same workspace. Then I changed the "#include" statements in the program where references to the old file name were made, so that it would now refer to the new name, and did a "Rebuild all". That's it!!!!
The rest is already known about the compiler saying it cannot open the newly named file.
I've already spent too much time on this problem, and what I'll end up doing, is simply create a new project and add in ALL the files I'll need, and resolve this issue that way.
Dev Studio needs some overhauling and I don't believe MS has any intention of doing that. In their view, "It's not broken enough."
William
Fortes in fide et opere!
|
|
|
|
|
Strange indeed. What happens if you reverse all of these changes such that the file has its old name and all references to the old file are put back in place?
Short of that, you might not even need to add the .H file to the project. For all new classes that I (not ClassWizard) create in my project, I only add the .CPP file. A #include statement with the corresponding .H file is all that's necessary.
|
|
|
|
|
WREY wrote:
...the program is saying it cannot find to open the file (even though the file is physically present in the same directory as the ".exe" file).
Which is usually the Debug or Release folder. Try moving the file up one level to the actual project's folder.
|
|
|
|
|
Thanks for replying.
No. The newly named file resides in the same folder as the ".dsp" file, which is a different folder than Debug or Release, but which ALL reside in the same directory.
If I'm not mistaken, my understanding is that an ".exe" file will automatically look up one level above, in the same directory where it resides (and any number of levels below [in the same directory]), to find the files it will need to access (which is why I said, "the file is physically present in the same directory as the '.exe' file").
William
Fortes in fide et opere!
|
|
|
|
|
WREY wrote:
Yes, I did delete the ".ncb" file followed by a "Rebuild all".
What about the .CLW, .APS, .PCH, .PDB, .ILK, .SBR, .BSC, and .OPT files. Does removing them help?
|
|
|
|
|
Thanks for replying.
No, I didn't go that far as to the removing of all those other files.
What I've done, is simply created another project and added in those files I'll be using, then I did a "Rebuild all" and everything went well. Now I can go on with my work.
It is sad that I'll never find out what would have made "Dev Studio" gotten itself out of this mess. The good news is that I won't have to waste anymore time thinking "Dev Studio" would have eventually gotten itself out of the mess.
The moral of the story is, "When it comes to 'Dev Studio' AppWizard, and ClassWizard, keep things simple, otherwise you'll pay with a hefty waste of hours."
Thanks for all your input, I appreciate them.
William
Fortes in fide et opere!
|
|
|
|
|
Hi everyone. I am implementing a project for my dissertation which will manipulate a database (Oracle 9). I have to use (Visual) C++ (industrial project, requirement) for which I am totally new (I have spent many hour for MSDN).I will also use CORBA or DCOM. I have post some of the problems mentioned here in separate threads but the problems persist and the deadline is near (I have two weeks yet). The problems are:
I implement a class which will act as a server. All clients will connect to this class. This class is responsible for manipulating the database. Although most operations work properly (Select, Update and Delete) I cannot add a new records. I use an MFC CRecordset derived class.
EmployeeRecordset for connecting and retrieving data from the database. A sample of this class is:
class EmployeesRecordset : public CRecordset
{
public:
CString m_EPONYMO1;
------------------------------------------------------------------------------------------------------------
Of course there are many fields.
I use a class Employee which will carry data from server to clients. This class has as many variables as the EmployeesRecordset but the data types are those of C++ (in case I use CORBA).
An example of Employee:
class Employee
{
private:
char* m_EPONYMO1;
public
char* getm_EPONYMO1(){return(m_EPONYMO1);}
void setm_EPONYMO1(char* surname1){m_EPONYMO1 = surname1;}
So far I don't use copy constructor and I don't have anything at constructor, destructor
------------------------------------------------------------------------------------------------------------
The ADDNEW method:
bool Service::AddNew(Employee e){
long id;
EmployeesRecordset records(db);
//Begin transaction
db->BeginTrans();
cout << "before opening" << endl;
//open the recordset only for adding records mode
if (db->CanUpdate()){
try{
//"SELECT * FROM [TEIDB].[T_YPALLHLON];"
if ((records.Open(CRecordset::dynaset, NULL,CRecordset::appendOnly))!=0){
cout << "recordset opened" << endl;
//if recordset is updateable add new record
if (records.CanAppend()){
//find the last YP_ID
records.MoveLast();
cout << (LPCSTR)records.m_HMER_PROSL.Format( "%A, %B %d, %Y" ) << endl;
cout << records.m_YP_ID<< endl;
cout << "LAST RECORDCOUNT" << " " << (LPCTSTR)records.m_EPONYMO1<< endl;
id = records.m_YP_ID + 1;
cout << id << endl;
records.AddNew();
records.SetFieldNull( NULL );
// cout << "set new values" << endl;
//copy new values
// CopyToRecordset(records,e);
records.m_ADDR1 = e.getm_ADDR1();
records.m_ADDR2 = e.getm_ADDR2();
records.SetFieldDirty(&records.m_ADDR1, TRUE);
records.SetFieldDirty(&records.m_ADDR2, TRUE);
// cout << "values set" << endl;
// cout << id<< endl;
if (records.Update()){
// cout << "Added" <<endl;
end="" transaction
="" records.close();
="" db-="">CommitTrans();
return (true);
}//end if
}//end if
}//end if
}//end of try
catch (CDBException cdbe){
cout << "exception raised" << endl;
records.Close();
db->Rollback();
return (false);
}//end of catch
catch (CMemoryException cme){
cout << "exception raised" << endl;
records.Close();
db->Rollback();
return (false);
}//end of catch
}//end if
else cout << "data cannot update" << endl;
cout << "end of addnew" << endl;
records.Close();
db->Rollback();
return(false);
}//end of AddNew
------------------------------------------------------------------------------------------------------------
the SELECT method of the Service(server) class is :
this method searches the database for the given employees.
vector<employee> Service::Select(char* surname){
Employee temp_e;
vector<employee> e;
EmployeesRecordset records(db);
CString str;
CString temp = (CString)surname;
cout << "Inside select" << endl;
/* //set filter
records.m_strFilter = "EPONYMO1 = ?";
//bind parameter
records.m_EPONYMO1Param = surname;
cout << LPCTSTR(surname) << endl;
*/
int i =0;
if (!temp.IsEmpty())
str = "SELECT * FROM [TEIDB].[T_YPALLHLON] WHERE EPONYMO1 = '" + (CString)surname + "';";
else str = "SELECT * FROM [TEIDB].[T_YPALLHLON];";
cout << (LPCTSTR)str << endl;
//open the recordset
try{
if (records.Open(CRecordset::dynaset,str,CRecordset::readOnly)!=0){
// test if recordset is empty
if( records.IsBOF( ) ) {
cout << "recordset empty" << endl;
records.Close();
temp_e.setstatus(false);
e.push_back(temp_e);
return (e);
}//end if
//if recorset is not empty copy data to Employees
while ( !records.IsEOF( ) ){
//copy data to employee
// CopyToEmployee(records, temp_e);
cout << (LPCTSTR)records.m_ADDR1 << endl;
temp_e.setm_ADDR1(records.m_ADDR1.GetBuffer(records.m_ADDR1.GetLength()));
temp_e.setm_ADDR2(records.m_ADDR2.GetBuffer(records.m_ADDR2.GetLength()));
temp_e.setm_YP_ID(records.m_YP_ID);
temp_e.setm_EPONYMO1(records.m_EPONYMO1.GetBuffer(records.m_EPONYMO1.GetLength()));
temp_e.setm_ONOMA(records.m_ONOMA.GetBuffer(records.m_ONOMA.GetLength()));
cout << temp_e.getm_ADDR1() << endl;
records.m_ADDR1.ReleaseBuffer(-1);
records.m_EPONYMO1.ReleaseBuffer(-1);
records.m_ONOMA.ReleaseBuffer(-1);
//copy object to vector
e.push_back(temp_e);
cout << e[i].getm_ADDR1() << endl;
i++;
records.MoveNext();
}//end of while
}//end if
}//end of try
catch (CDBException cdbe){
return (e);
records.Close();
}//end of catch
catch (CMemoryException cme){
cout << "exception raised" << endl;
records.Close();
return (false);
}//end of catch
cout << "Exit select" <<endl;
records.close();
=""
="" return(e);
}="" end="" of="" select
select="" and="" addnew="" belong="" to="" the="" object="" service.="" in="" its="" constructor="" service="" accepts="" as="" an="" argument="" a="" cdatabase="" reference,="" which="" uses="" for="" initializing="" crecordset="" derived="" classes.
------------------------------------------------------------------------------------------------------------
this="" is="" how="" i="" call="" these="" methods:="" give="" example="" select="" because="" when="" although="" can="" print="" most="" data="" types="" cannot="" (cout)="" contents="" strings.="" returns="" vector="" employees.
cdatabase="" data;
="" try{
="" if="" (!data.isopen())="" connection="data.OpenEx(_T("DSN=TEIDB;UID=DBADMIN;PWD=DBADMIN"),0);
" cout="" <<="" "connection="" established"="" endl;
="" }="" try
="" catch(="" cdbexception="" cdbe)="" {
="" failed";
="" catch
="" (connection){
="" "service"="" endl;="" service
="" serv(&data),serv1(&data);
="" "constructing="" employee"="" endl;
="" employee="" e;
="" cstring="" el="ELA" ;
="" k="KATI" e.setm_addr1(el.getbuffer(el.getlength()));
="" e.setm_eponymo1(k.getbuffer(k.getlength()));
="" el.releasebuffer(-1);
="" k.releasebuffer(-1);
="" e.getm_addr1()<<="" e.getm_eponymo1()="" "calling="" select"="" vector<employee=""> emp = serv.Select("KATI");
cout << "size of vector " << emp.size() << endl;
// Print contents of the Vector.
cout << "contents of vector" << endl;
for (int size = 0; size < emp.size(); size++)
{
cout << emp[size].getm_EPONYMO1() << " " << emp[size].getm_YP_ID() << endl;
}//end for
e.setm_ADDR2("ELA");
e.setm_EPONYMO1("KATI");
e.setm_ADDR1("FANTASTIKH");
cout << "calling addnew" << endl;
bool add = serv.AddNew(e);
if (add) cout << "added" << endl;
else cout << "not added" << endl;
data.Close();
In the AddNew method I always het a runtime error when calling records.Update();
So the problems are:
1) AddNew doesn’t work. I have made a lot of changes to the OpenEx method but nothing works.
2) I cannot print the string(char*) returned from the vector.
While inside the function Select all strings are printed normally!!!!!!!!!!!!!!!!!!!
3) How can I convert a COleDateTime to CTime. I use the following code (with a number of different formats) but it doesn’t work
COleDateTime oleDt;
cout << "oledt" << endl;
CString str = "8:30:00 Jan. 25, 1996";
oleDt.ParseDateTime(str.Left(15));
cout << "parse date" << endl;
cout << oleDt.Format("%H %M %S") << endl;
SYSTEMTIME st;
cout << "systemtime" << endl;
oleDt.GetAsSystemTime(st);
cout << "getassystemtime" << endl;
CTime myTime(st);
cout << "CTime" << endl;
cout << (LPCTSTR)myTime.Format( "%A, %B %d, %Y" ) << endl;
4) Which values should I use to change the mode of a recordset to pessimisti or optimistic? I use the SetLockingMode(); functions with arguments either (optimistic, pessimistic) or (0,1) but nothing works.
5) Since I have to use a distributed technology which one is more flexible and easier to use (CORBA or DCOM)? I have used before CORBA but with Java. I also have some thoughts about the compatibility between CORBA orbs (I have downloaded omniOrb fro AT&T) and Visual Studio (MFC Classes)?
I apologise for the length of the ‘essay’ but I am trying three days to solve the above problems and I cannot find any solution
|
|
|
|
|
Since this is for a school project, I am hesitant to help, but I will throw you some bones
1) You are using a try/catch around your call to records.AddNew() , but you are not examining the CDBException m_strError or m_strStateNativeOrigin variables. These may give you a new clue as to why your call fails.
2) You are returning a variable, vector e , which is on the local stack.
3) Your problem is in this line: oleDt.ParseDateTime(str.Left(15));
4) How do you know they are not working? You must have two or more connections trying to Edit/Update the same record to see it work.
Roger Stewart
"I Owe, I Owe, it's off to work I go..."
|
|
|
|
|
3) With the exception of not knowing the year, this code works fine, so you'll have to further define "it doesn't work."
|
|
|
|
|
hey everyone thanks for replying.
I solved all the problems except the one that tries to add a new records inm the database, which I will work to. All the other operations (select, delete record, update one) are tested and work properly. I find it very bizzare that the add new is not working because I ve checked the code not only from MSDN but from various e-books and sites and all semm ok.
|
|
|
|
|
thanks all.
I ve solved all the problems except the one of adding a new record.
With regards
Vassilis Papoulidis
|
|
|
|
|
My visual C++ book uses these lines several times:
CRect m_EnclosingRect;<br />
CPoint Start, End;<br />
<br />
m_EnclosingRect = CRect(Start, End);
At first, they seemed simple enough, but after encountering the last line several times:
m_EnclosingRect = CRect(Start, End);
I finally realized I'm not familiar with that notation. The right side of the equals sign is a constructor, so how can it return anything to assign to m_Enclosing Rect? The method I'm familiar with for doing that is this:
CRect aRect(Start, End);<br />
m_EnclosingRect = aRect;
|
|
|
|
|
CRect(Start, End) is an instance of a CRect object, it has just not been assigned to a formal variable like CRect aRect(Start, End) has.
|
|
|
|
|
Have a read up on Copy Constructors. Do a Google search should help out.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Thanks for the replies.
I'm not sure how the copy constructor is involved. My book says:
The copy constructor is called when a class object is created and initialized with an existing object of the same class, or when an object is passed to a function by value.
m_EnclosingRect isn't being created in the line in question.
|
|
|
|
|
It was around 6.40am when I replied and my brain had quite kicked into gear, and probably still hasn't.
David was closer. The constuctor instantiates a CRect and the assignment operator copies it.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|