Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ColdPie
Jun 9, 2006

I have a question about inheritance in C++. The C++ FAQ says that inheritance is not for code re-use, but rather for polymorphism and other related features. This seems to conflict with the old "Shape" example (class Shape contains a Position method and related variables, Circle and Rectangle inherit from Shape and inherit this method and data, so more code re-use). Is using inheritance for this reason wrong? If so, why? What am I missing here?

Adbot
ADBOT LOVES YOU

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

WalletBeef posted:

What is the best, free, windows C++ compiler?

As far as I know, your choices are basically Visual Studio Express or MinGW. Express has the advantage that it's closer to the full, for-pay version of Visual Studio, which is what all Windows software ever is built with, but the disadvantage that it's missing some things and lots of documentation or other software you might want to work with assumes you have those things. MinGW is the Windows port of gcc, the compiler used on every OS except Windows, which is completely free itself, so documentation about gcc will usually transfer right over.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Visuacl C++ 2008 Express Edition

It has the added benefit of being able to create nice GUI's.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

ColdPie posted:

I have a question about inheritance in C++. The C++ FAQ says that inheritance is not for code re-use, but rather for polymorphism and other related features. This seems to conflict with the old "Shape" example (class Shape contains a Position method and related variables, Circle and Rectangle inherit from Shape and inherit this method and data, so more code re-use). Is using inheritance for this reason wrong? If so, why? What am I missing here?

The point is that Position and related variables logically belong to all the various subclasses of Shape. If you had a method that happened to be coded very similarly for Circles and Rectangles, but not for Squares, you wouldn't want to add a base class that both Circle and Rectangle inherit from but Square doesn't just to hold this method, because that would make no sense. You also wouldn't put the Circle and Rectangle version in the base class and then have Square override it, because the Circle and Rectangle version doesn't apply to all Shapes so it has no reason being in the base class. (You also wouldn't just duplicate the code in the two classes - make a standalone friend function that's called from both, or something.)

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

MEAT TREAT posted:

Visuacl C++ 2008 Express Edition

It has the added benefit of being able to create nice GUI's.

Uh, Visual C++ doesn't have a monopoly on nice GUI's. I'm not even sure what you mean by that - a compiler that couldn't be used to compile a GUI is pretty useless.

ColdPie
Jun 9, 2006

JoeNotCharles posted:

The point is that Position and related variables logically belong to all the various subclasses of Shape. If you had a method that happened to be coded very similarly for Circles and Rectangles, but not for Squares, you wouldn't want to add a base class that both Circle and Rectangle inherit from but Square doesn't just to hold this method, because that would make no sense. You also wouldn't put the Circle and Rectangle version in the base class and then have Square override it, because the Circle and Rectangle version doesn't apply to all Shapes so it has no reason being in the base class. (You also wouldn't just duplicate the code in the two classes - make a standalone friend function that's called from both, or something.)

Oh, I get you. That makes sense. Thank you.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

JoeNotCharles posted:

Uh, Visual C++ doesn't have a monopoly on nice GUI's. I'm not even sure what you mean by that - a compiler that couldn't be used to compile a GUI is pretty useless.

It's also an IDE that lets you create windows forms and see what they are going to look like.

edit: IDE != Compiler, but it still a benefit you get with Visual Studio.

Janitor Prime fucked around with this message at 19:26 on Mar 5, 2008

defmacro
Sep 27, 2005
cacio e ping pong
I considered making a separate post for this, but it'd probably be better here.

Here's the short version: I need a ton of help compiling this for a research group I'm involved with. I'm prepared to pay for help, as I have no idea what I'm doing, and very little time to do it in.

Long version: I started working for a research group doing bioinformatics stuff. The work is cool, but since I'm a CS major, I've gotten pigeonholed into maintaining the above project on top of all my other responsibilities. I said I could play around with it, but I really wanted to work on other stuff. Unfortunately, the machine which had a compiled version died and we are in urgent need of getting the code up and running on other machines. It's midterm week(s), and I'm swamped to hell. The only build instructions left "just use KDevelop 2.3" despite it being built on top of autotools. So, in short, I need this, and I need it fast. I don't need an elegant fix -- although one would be nice -- just something that works.

I have never worked with C++ or autotools, and I'm getting super frustrated. I have no idea how easy/difficult this is, but when I have more time, I want to make it much easier to compile (like, ./configure && make && make install easy). If it's a larger problem than I currently think, I'm more than willing to pay a bit, considering the urgency of this.

Please help :(.

defmacro fucked around with this message at 20:47 on Mar 5, 2008

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

GT_Onizuka posted:

I have never worked with C++ or autotools, and I'm getting super frustrated. I have no idea how easy/difficult this is, but when I have more time, I want to make it much easier to compile (like, ./configure && make && make install easy). If it's a larger problem than I currently think, I'm more than willing to pay a bit, considering the urgency of this.

It's almost that simple already. Install automake and autoconf, then:

code:
make -f Makefile.dist && ./configure && make && make install
Makefile.dist is a KDE-ism which you probably wouldn't have known to look for. Really, would it have been that hard for them to put the two lines about in the INSTALL or README files?

defmacro
Sep 27, 2005
cacio e ping pong

JoeNotCharles posted:

It's almost that simple already. Install automake and autoconf, then:

code:
make -f Makefile.dist && ./configure && make && make install
Makefile.dist is a KDE-ism which you probably wouldn't have known to look for. Really, would it have been that hard for them to put the two lines about in the INSTALL or README files?

Oh wow, that certainly helped out quite a bit. I'm getting some errors, but they seemed to be related to the libraries. Considering how old things are, I suppose I shouldn't be too surprised. Thanks again, I'm almost on my way!

EDIT: I know this is a long shot, as it's some random library, but I figure it's worth a shot. Here's the error I get:
code:
plotview.o: In function `Min_circle_2<Point*>':
/usr/include/CGAL/Min_circle_2.h:326: undefined reference to `CGAL::default_random'
plotview.o: In function `void CGAL::circumcenter_translateC2<float>(float const&, float const&, float const&, float const&, float&, float&)':
/usr/include/CGAL/constructions/kernel_ftC2.h:60: undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
plotview.o: In function `CGAL::Min_circle_2<CGAL::Min_circle_2_traits_2<CGAL::Cartesian<float> > >::compute_circle()':
/usr/include/CGAL/Min_circle_2.h:263: undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
collect2: ld returned 1 exit status
make[3]: *** [wcurve] Error 1
make[3]: Leaving directory `/home/ynadji/wcurve/wcurve'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/ynadji/wcurve/wcurve'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/ynadji/wcurve'
make: *** [all] Error 2
All the errors seem to be within CGAL, so I haven't the slightest clue what's going on. Any ideas?

defmacro fucked around with this message at 07:13 on Mar 6, 2008

illamint
Jun 26, 2005

According to The Oxford English Dictionary, the word "snapshot" was originally a hunting term.
I'm fairly new to C++ and I'm wondering what the regular expression library du jour is. For a project in my CS class, we have to parse fairly large files (right now I'm going line-by-line with the regular expression "^([A-Za-z0-9]+),([A-Za-z0-9]*),([A-Za-z0-9]*),(s?f?|f?s?);$"), and I'm using regex.h which is unfortunately incredibly slow. I see that there's Boost.Regex, but we have to hand in our source code at the end of the project and I'm not sure that it's feasible to merge the Boost shared library stuff into my makefiles just for this. Should I just parse it by hand? Is there a better solution? I'm used to being able to just go to the Java or Python docs and glance at the syntax in the manual but I'm having kindof a hard time doing that with C++.

more falafel please
Feb 26, 2005

forums poster

GT_Onizuka posted:

Oh wow, that certainly helped out quite a bit. I'm getting some errors, but they seemed to be related to the libraries. Considering how old things are, I suppose I shouldn't be too surprised. Thanks again, I'm almost on my way!

EDIT: I know this is a long shot, as it's some random library, but I figure it's worth a shot. Here's the error I get:
code:
plotview.o: In function `Min_circle_2<Point*>':
/usr/include/CGAL/Min_circle_2.h:326: undefined reference to `CGAL::default_random'
plotview.o: In function `void CGAL::circumcenter_translateC2<float>(float const&, float const&, float const&, float const&, float&, float&)':
/usr/include/CGAL/constructions/kernel_ftC2.h:60: undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
plotview.o: In function `CGAL::Min_circle_2<CGAL::Min_circle_2_traits_2<CGAL::Cartesian<float> > >::compute_circle()':
/usr/include/CGAL/Min_circle_2.h:263: undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
collect2: ld returned 1 exit status
make[3]: *** [wcurve] Error 1
make[3]: Leaving directory `/home/ynadji/wcurve/wcurve'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/ynadji/wcurve/wcurve'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/ynadji/wcurve'
make: *** [all] Error 2
All the errors seem to be within CGAL, so I haven't the slightest clue what's going on. Any ideas?

It looks like either the headers are out of date with the libraries you're linking in (unlikely), or you're not linking in the library correctly.

That Turkey Story
Mar 30, 2003

illamint posted:

I see that there's Boost.Regex, but we have to hand in our source code at the end of the project and I'm not sure that it's feasible to merge the Boost shared library stuff into my makefiles just for this. Should I just parse it by hand? Is there a better solution? I'm used to being able to just go to the Java or Python docs and glance at the syntax in the manual but I'm having kindof a hard time doing that with C++.

There's also regex in TR1 that's based off of Boost.Regex and is probably supported by your compiler's standard library already.

Scaevolus
Apr 16, 2007

illamint posted:

the regular expression "^([A-Za-z0-9]+),([A-Za-z0-9]*),([A-Za-z0-9]*),(s?f?|f?s?);$"),

Do all the lines in the file match this? If so, a regex is overkill.

vv also overkill. Writing a DFA for this would be very easy.

Scaevolus fucked around with this message at 02:19 on Mar 7, 2008

Entheogen
Aug 30, 2004

by Fragmaster

illamint posted:

I'm fairly new to C++ and I'm wondering what the regular expression library du jour is. For a project in my CS class, we have to parse fairly large files (right now I'm going line-by-line with the regular expression "^([A-Za-z0-9]+),([A-Za-z0-9]*),([A-Za-z0-9]*),(s?f?|f?s?);$"), and I'm using regex.h which is unfortunately incredibly slow. I see that there's Boost.Regex, but we have to hand in our source code at the end of the project and I'm not sure that it's feasible to merge the Boost shared library stuff into my makefiles just for this. Should I just parse it by hand? Is there a better solution? I'm used to being able to just go to the Java or Python docs and glance at the syntax in the manual but I'm having kindof a hard time doing that with C++.

use lex

DFAs are harder to implement in C++ than writing a lexer that can do the same thing. Lexer outputs DFA anyway. Just define your reg expression and associate a rule for when lexer finds it (that is what C++ code to execute), and voila, you are done.

Entheogen fucked around with this message at 14:53 on Mar 7, 2008

illamint
Jun 26, 2005

According to The Oxford English Dictionary, the word "snapshot" was originally a hunting term.

Scaevolus posted:

Do all the lines in the file match this? If so, a regex is overkill.

vv also overkill. Writing a DFA for this would be very easy.
Match this? As in, always match? I mean, ideally they would, but we're supposed to catch syntax errors in input. It's funny, actually, this specific part of the project is an interpreter for a specific DFA language, so yeah, I thought about a DFA, but I've always just used regular expressions for things like this due to ease-of-use. I guess I'll just write up a DFA for it, since it doesn't really look like there's a library that I can assume exists on the instructor's computer.

Eararaldor
Jul 30, 2007
Fanboys, ruining gaming since the 1980's
I'm not entirely sure if this is the right place to post this but I'll give it a shot. Basically creating a c# web application. After they submit information into the database, a email is needed to be dispatch displaying the contents that was just added.

Anyway I get this error and its anoying me :colbert:
Format of the initialization string does not conform to specification starting at index 0.

It shows at the connection string.

code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Net.Mail;
using System.Globalization;
using BEC.WebOrder;



/////start of app


public partial class Apply2 : System.Web.UI.Page
{
    private string block1;
    private string block2;
    private string block3;
        private void GetDataFromDatabase()
    {
        SqlConnection scon = new SqlConnection("<%$ ConnectionStrings:Myconnectionstring %>");
        SqlCommand scmd = new SqlCommand("SELECT Column1, Column2, Column3 FROM table", scon);
        SqlDataReader sdr;
        try
        {
            scon.Open();
            sdr = scmd.ExecuteReader();
            sdr.Read();
            block1 = sdr["column1"].ToString();
            block2 = sdr["column2"].ToString();
            block3 = sdr["column3"].ToString();
            
        }
        catch (Exception ex)
        {
            throw new Exception("Error occured: " + ex);
        }
        finally
        {
            scon.Close();
        }
    }
    /////Get Message
    private string GetMessage()
    {
        GetDataFromDatabase()
        string message = block1 + "<br />" + block2 + "<br />" + block3;
        return message;
    }

    //////End get message
   


    protected void sendButton_Click(object sender, EventArgs e)
    {

    //When button is clicked, sqldatasource is inserted into the database. Status label displays a message confirming.

        SqlDataSource.Insert();
        statusLabel.Text = "Your Booking has been sent. Your receive a Email notifying you of its status.";

        ///Code to send of email to(fakefake.com)
        MailMessage message = new MailMessage();
        MailAddress SendFrom = new MailAddress("Fake@fake.com");
        message.From = SendFrom;
        message.To.Add("Fakefake.com");
        message.Bcc.Add("Fakefake.com");
        message.Subject = "Read me";

///GetMessage makes the Get Message section above work
        message.Body = GetMessage();
        message.IsBodyHtml = true;
        SmtpClient client = new SmtpClient();
        client.Host = "My webserver";
        client.Send(message);

csammis
Aug 26, 2003

Mental Institution

Eararaldor posted:

I'm not entirely sure if this is the right place to post this

From the list of megathreads, you want the .Net (C#, VB.NET [VB 2003, 2005, and 2008]) Questions Megathread megathread.

Eararaldor
Jul 30, 2007
Fanboys, ruining gaming since the 1980's

Ah thanks. BTW problem solved anyway.

Mornacale
Dec 19, 2007

n=y where
y=hope and n=folly,
prospects=lies, win=lose,

self=Pirates
I suspect that I'm entirely retarded for this problem, but:

I am finding myself unable to create a bitset. I've been using this page as reference; if there is a better one that I should be using, that'd be very helpful.

code:
#include <bitset>

#define ITEM_SIZE 1000

bitset<8> itemBit;
The include line works fine, so I'm not somehow missing the bitset definition. However, I get "expected constructor, destructor, or type conversion before ‘<’ token" when I try to actually create the object. I want it to eventually be a bitset of larger length, but I did 8 just so I could copy/paste from the example in my link above.

Any ideas would be extraordinarily appreciated.

e: Problem solved. Thanks. Pay no more attention to the C++ n00b behind the curtain.

Mornacale fucked around with this message at 04:32 on Mar 9, 2008

Vanadium
Jan 8, 2005

You seem to be missing std:: in front of bitset.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

Mornacale posted:

e: Problem solved. Thanks. Pay no more attention to the C++ n00b behind the curtain.

The guy below you already posted, but in general, people, if you solve the problem without they board's help, please post the solution! Other people might be wondering what it was.

Super Dude
Jan 23, 2005
Do the Jew
How can I add elements to the beginning of a vector? I essentially want to merge a vector and a string, putting one ahead of the other. I was going to just take the characters from the string, starting with the end, and add them to the beginning of the vector. Unfortunately, I can only find the push_back function, which adds it to the end. Would it be ok to make the string into a vector, then tack on the other vector?

edit: Thanks Milde.

Super Dude fucked around with this message at 05:16 on Mar 9, 2008

Allie
Jan 17, 2004

Super Dude posted:

How can I add elements to the beginning of a vector? I essentially want to merge two vectors of different length, putting one ahead of the other.

a.insert(a.begin(), b.begin(), b.end());

That will insert all the elements from b into the beginning of a.

Super Dude
Jan 23, 2005
Do the Jew
If I have a vector 'alphabet', and I want to erase a single element at index j, is this the correct syntax?

alphabet.erase(j,1);

Allie
Jan 17, 2004

Super Dude posted:

If I have a vector 'alphabet', and I want to erase a single element at index j, is this the correct syntax?

alphabet.erase(j,1);

There's erase(iterator pos) and erase(iterator first, iterator last). The latter erases a range of elements. You want the former (and with an iterator).

You should bookmark this http://www.sgi.com/tech/stl/Vector.html. :)

Super Dude
Jan 23, 2005
Do the Jew
using erase(j) gives this error:

code:
error C2664: 'std::_Vector_iterator<_Ty,_Alloc> std::vector<_Ty>::erase(std::_Vector_iterator<_Ty,_Alloc>)' : cannot convert parameter 1 from 'int' to 'std::_Vector_iterator<_Ty,_Alloc>'1> 

Allie
Jan 17, 2004

Yes, because you need an iterator, not an int. If you really want to do it by index, try alphabet.erase(alphabet.begin() + j). But if j is just a loop counter, you should be using an iterator instead of a counter.

Incoherence
May 22, 2004

POYO AND TEAR

Super Dude posted:

using erase(j) gives this error:

code:
error C2664: 'std::_Vector_iterator<_Ty,_Alloc>
 std::vector<_Ty>::erase(std::_Vector_iterator<_Ty,_Alloc>)'
 : cannot convert parameter 1 from 'int' to 'std::_Vector_iterator<_Ty,_Alloc>'1> 
erase takes an iterator parameter. You probably want alphabet.erase(alphabet.begin()+j). Why is it this hard? Because the STL is weird.

more falafel please
Feb 26, 2005

forums poster

Incoherence posted:

erase takes an iterator parameter. You probably want alphabet.erase(alphabet.begin()+j). Why is it this hard? Because the STL is weird.

Because iterators are better. Why? 'Cos. :colbert:

Vanadium
Jan 8, 2005

more falafel please posted:

Because iterators are better. Why? 'Cos. :colbert:

If you implement your std::whatever-algorithms using indexes instead of iterators they will be O(n^2) for linked lists :colbert:

Entheogen
Aug 30, 2004

by Fragmaster

Milde posted:

There's erase(iterator pos) and erase(iterator first, iterator last). The latter erases a range of elements. You want the former (and with an iterator).

You should bookmark this http://www.sgi.com/tech/stl/Vector.html. :)

http://www.cppreference.com/

That website is also really awesome for general references on C/C++ standard libraries and other stuff. I use it a lot.

Not So Fast
Dec 27, 2007


At the moment, I'm getting a lot of linker errors when Visual Studio is trying to build a class template. The code compiles fine and dandy, but linker errors are too confusing for me to deduce. The template takes in two types, like so:

code:
List<Node, string>	craftlist;
but I get the same linker error messages when I reduce it to a single class template, so I know it's not the fact that I'm using multiple typenames.

I'm getting LNK2019 errors. I've looked on the Microsoft resource website, but I couldn't see any similarity between the examples they gave and what I was doing.

The errors:

http://pastebin.ca/935705

So my question is, where do I start if I want to fix these errors? As far as I can tell, all my code is spelled correctly.

EDIT: Moved the errors to pastebin to avoid table breaking.

Not So Fast fucked around with this message at 22:10 on Mar 9, 2008

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Jesus dude, that is some serious table breaking.

Also it looks like you're trying to define your template member functions in a separate compilation unit (.cpp file). C++ doesn't allow that. You need to define them in the header.

Not So Fast
Dec 27, 2007


Ah, that fixed it, thanks. Yeah, I had the functions defined in a .cpp file, but didn't realise that it wasn't referenced at all in the header file or the main source code.

Plastic Jesus
Aug 26, 2006

I'm cranky most of the time.

Super Dude posted:

How can I add elements to the beginning of a vector? I essentially want to merge a vector and a string, putting one ahead of the other. I was going to just take the characters from the string, starting with the end, and add them to the beginning of the vector. Unfortunately, I can only find the push_back function, which adds it to the end. Would it be ok to make the string into a vector, then tack on the other vector?

edit: Thanks Milde.

I know that this was resolved, but why are you using a vector instead of a deque when you know that you'll be inserting at the beginning? Deques are designed to grow from both ends whereas vectors are not.

defmacro
Sep 27, 2005
cacio e ping pong

more falafel please posted:

It looks like either the headers are out of date with the libraries you're linking in (unlikely), or you're not linking in the library correctly.

Yeah, I'm just a retard. Oh well, I got it working at the very least. Thanks guys.

Thug Bonnet
Sep 22, 2004

anime tits ftw

Is it possible to examine the memory space a program resides in from within the program?

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Thug Bonnet posted:

Is it possible to examine the memory space a program resides in from within the program?

...yes, programs can read their own memory. But that can't possibly be what you mean to be asking. What are you trying to do?

Adbot
ADBOT LOVES YOU

Thug Bonnet
Sep 22, 2004

anime tits ftw

ShoulderDaemon posted:

...yes, programs can read their own memory. But that can't possibly be what you mean to be asking. What are you trying to do?

No, that's what I'm asking! :) I'm just kind of curious, honestly. But how would the program know "where it is" in memory, how large it is, etc. Also, I assume it's not necessarily contiguous..

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply