Problems creating a new class

This is a discussion on Problems creating a new class within the C++ Programming forums, part of the General Programming Boards category; Howdy, I'm working on a web server in C++ at the moment, and I'm having a slight problem (read on ...

  1. #1
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986

    Problems creating a new class

    Howdy,

    I'm working on a web server in C++ at the moment, and I'm having a slight problem (read on even if you don't know anything about web servers, the problems not with that).

    I have created a class called Connection, which stores data on every request made while it is handled. When a new request is made, I want to create a new Connection, and delete it once the request is finished processing.

    This is what I wrote:
    Code:
    Connection * newRequest(SockFD) = new Connection;
    The argument the default constructor takes is the socket descriptor, but dont worry about that. When I have:
    Code:
    Connection newRequest(SockFD);
    It all runs fine.

    The error I get is:
    Cannot convert 'int' to 'Connection *'
    Declaration syntax error.

    Any help on this is greatly appreciated, I know its a silly mistake I've made, but I can't see it. Thanks

    PS: The class's constructor that I made takes an argument (SockFD in this case, which is an int). There is no second constructor which takes no arguments. Does this make any difference?

  2. #2
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Thanks very much, it worked but now when I get a connection I get an alert box saying 'The instruction referenced at 0xsomething could..... I'm sure you know the one.

    This is the three lines used:
    PHP Code:
              int Sockfd2 accept(Sockfd, (struct sockaddr *) &clientAddress, &size);
              
    Connection NewRequest = new Connection(Sockfd2);
              
    cout << "We got a new connection!";
              
    delete NewRequest
    I dont have a destructor defined, could that be a problem? But anyhow it seems that it gets the error as soon as it tries to create the new class.

    Any ideas on why this could be happening? My understanding of pointers is not all that great.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Seems like there's some uninitialized pointer/undersized buffer in the constructor of the class?
    It's hard to say without seeing the code..

  4. #4
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    lol, thanks very much knutso. I was just copying my code here when I realised I had char * Buffer; rather than char Buffer[1000]. So I changed that and now it works fine thanks very much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a Window Class
    By Dark_Phoenix in forum Windows Programming
    Replies: 2
    Last Post: 12-07-2008, 07:45 PM
  2. Class declaration problems
    By scwizzo in forum C++ Programming
    Replies: 0
    Last Post: 12-01-2008, 07:47 PM
  3. Linking problems, class problems
    By Kheila in forum C++ Programming
    Replies: 12
    Last Post: 11-22-2005, 01:47 AM
  4. Problems with my custom string class
    By cunnus88 in forum C++ Programming
    Replies: 15
    Last Post: 11-15-2005, 08:21 PM
  5. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 03:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21