Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 11th, 2008, 01:31 AM
Authorized User
 
Join Date: Jul 2003
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default C++ question

I have three C++ files,like follows:
/*Test.h*/
Code:
#include <iostream.h>
class Test{
public:
   Test();
};
/*Test.cpp*/
Code:
#include "Test.h"
Test::Test(){
   cout<<"Test called";
}
/*a.cpp*/
Code:
#include "Test.h"
int main(int argc, char* argv[])
{
   Test abc=new Test();
   return 0;
}
When I run a.cpp,it raise following error:
[C++ Error] a.cpp(4): E2034 Cannot convert 'Test *' to 'Test'

Why raise above error? How to correct my code?
Thanks

Reply With Quote
  #2 (permalink)  
Old July 3rd, 2008, 07:02 AM
Registered User
 
Join Date: Jul 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

As far as i Can tell the Problem is the Line :
  Test abc=new Test();
C++ expects a pointer when allocating memory via the new Operator.

To Create an instance of a Class
  Test abc;
should be enough.


Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
question maheshraju ASP.NET 2.0 Basics 3 March 13th, 2008 08:54 AM
Question Ashwini Classic ASP Databases 3 January 10th, 2006 07:20 AM
Question? Calibus Classic ASP Databases 8 August 6th, 2004 08:25 AM
a question gorji C++ Programming 2 August 11th, 2003 07:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.