• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

How do I access my array containing values from main? I'm trying to pass in values to quicksort function. But I'm having problems. I made a getArray member function that returns the array with a pointer. And when I try to pass it in to quicksort function from main, I get errors telling me "invalid conversion from int to int*". So I'm guessing the error that is causing me some trouble was the fact that I was attempting to pass array of pointers to an integer to an integer data type of my array.

You should post your actual code.
 
Can I PM message someone my code instead? It's an homework assignment.

Can you make up some code that only has a main function and one extra sample function that has the same signature (return type and argument list) as the one you're trying to call, but doesn't contain anything else? Like:

Code:
void foo(int *array) {
}

int main(int argc, char **argv) {
  foo(/* something */);
  return 0;
}
 
Can you make up some code that only has a main function and one extra sample function that has the same signature (return type and argument list) as the one you're trying to call, but doesn't contain anything else? Like:

Code:
void foo(int *array) {
}

int main(int argc, char **argv) {
  foo(/* something */);
  return 0;
}

Something like this:
Code:
int main(){
    QuickSort q;
    q.quicksortAscending(r.getArrayofIntegers(), 0, size-1);
}

int QuickSort::getArrayofIntegers(){
	return *arr;
}

int QuickSort::quicksort(int arr, int l, int r){
	if(l < r){
		int q = partition(arr, l, r);
		quicksort(arr, l, q-1);
		quicksort(arr, q+1, r);
	}
}
 
Something like this:
Code:
int main(){
    QuickSort q;
    q.quicksortAscending(r.getArrayofIntegers(), 0, size-1);
}

int QuickSort::getArrayofIntegers(){
	return *arr;
}

int QuickSort::quicksort(int arr, int l, int r){
	if(l < r){
		int q = partition(arr, l, r);
		quicksort(arr, l, q-1);
		quicksort(arr, q+1, r);
	}
}
getArrayOfIntegers is an int return type, but you're returning a pointer. Change the return type to int*. Also, in quicksort you're only accepting an int when you need a pointer to an array of ints.

That specific error message is merely telling you you're giving it a type it wasn't expecting.
 
getArrayOfIntegers is an int return type, but you're returning a pointer. Change the return type to int*. Also, in quicksort you're only accepting an int when you need a pointer to an array of ints.

That specific error message is merely telling you you're giving it a type it wasn't expecting.

Okay. I compiled, and did not give me errors. I'm trying to return a sorted array in ascending order. Also, I'm trying to return a sorted array in descending order. I'm not sure what I need to do. It only returned one number instead of the rest of the elements in the array.
 

wolfmat

Confirmed Asshole
What are you doing way back there in pre-2012 land?
Late 2009 white unibody MacBook... Yosemite is free, but stupid with this computer. Mountain Lion is not free and brinks on being inacceptable with this machine (going by reviews).
Mavericks is free, but also probably beachball territory, and it's only downloadable in the Mac dev center -- I am not a member anymore though.

Pre-2012 land it is.
 
Okay. I compiled, and did not give me errors. I'm trying to return a sorted array in ascending order. Also, I'm trying to return a sorted array in descending order. I'm not sure what I need to do. It only returned one number instead of the rest of the elements in the array.

I know it's a homework assignment, but if you want help you're going to have to post more code. You're calling quicksortAscending(), but you only have a quicksort function for me to see (which is never called). Your quicksort function never returns anything despite being of type int, and you're using raw pointers to sort the function recursively which can be dangerous.
 

V_Arnold

Member
It is frustrating that I cant find any answer to why the "[" character cant be used in Visual Studio Code.

It works fine in every single other program, and the "]" character works in the Code too.

Just not the left one. I am not going to handicap myself over this, so back to Brackets for me until I find some solution online :(
 
It is frustrating that I cant find any answer to why the "[" character cant be used in Visual Studio Code.

It works fine in every single other program, and the "]" character works in the Code too.

Just not the left one. I am not going to handicap myself over this, so back to Brackets for me until I find some solution online :(

You should try asking on StackOverflow. Probably the people responsible for VSC are watching it.
 
I know it's a homework assignment, but if you want help you're going to have to post more code. You're calling quicksortAscending(), but you only have a quicksort function for me to see (which is never called). Your quicksort function never returns anything despite being of type int, and you're using raw pointers to sort the function recursively which can be dangerous.

I stopped focusing on this homework since my instructor posted another homework due next week and it looks overwhelming.
 

MiszMasz

Member
It is frustrating that I cant find any answer to why the "[" character cant be used in Visual Studio Code.

It works fine in every single other program, and the "]" character works in the Code too.

Just not the left one. I am not going to handicap myself over this, so back to Brackets for me until I find some solution online :(

Any help? I know it's for full-fat VS but still:
http://stackoverflow.com/questions/9324691/cant-type-certain-square-brackets-in-visual-studio-2010-resharper
http://n3wjack.net/2012/11/02/square-brackets-not-working-in-visual-studio-2010-and-how-to-fix-that/
 

V_Arnold

Member

The Code version sadly has a totally different, minimalistic keyboard shortcut option, where you cant seem to remove default bindings, only override them. I tried going this route, but to no luck so far.

You should try asking on StackOverflow. Probably the people responsible for VSC are watching it.

Did that. Awaiting results :)
 
Grab some energy drinks and knock them both out tonight haha.
But really, if you have specific questions, we're here to help.

Sorry for not mentioning this, but the homework was due last night. I'm fine with what I have so far. Right now the homework that's due next week is what I'm concerned with now. There are two problems. For the first problem, I have to implement my own version of class vector using dynamic arrays. The second one is about linked lists. So yeah, it's going to be...fun...
it's going to be a disaster.
 
Grab some energy drinks and knock them both out tonight haha.
But really, if you have specific questions, we're here to help.

Plus, from what I can infer from the code you pasted it looks like the problem isn't as hard as you think it is. Being as specific as possible will help us work you through the problem.

EDIT: Uncanny response time lol. Sorry to hear that.
 

Sandfox

Member
For you guys with jobs in the CS field do you guys have any tips for getting practical experience in anticipation of working for one of the big companies or something similar?
 
For you guys with jobs in the CS field do you guys have any tips for getting practical experience in anticipation of working for one of the big companies or something similar?

Internships, open source projects, and hobby projects. That's all you can do. Use that experience to prove you can get up to speed quickly.

Practical experience doesnt matter all that much considering you'll probably be relearning with each job shift. No company has the same standards, coding style, etc. As well, each problem domain has its own unique twists. Business App Development is different from Game Development. Within Business App Dev, some companies develop extensions to larger products. Other companies develop complete turnkey solutions for a given vertical. Add into that web based business apps vs rich native client business apps. You can see how it quickly becomes pointless to put too much stock into practical experience.
 
Code:
size_type capacity( ) const;

What's size_type? Is it some kind of data type? What statements allows me to make sure that I return the amount of elements that the vector contains without allocating more storage/memory?

Code:
void shrink_to_fit(
);

I'm not sure if this is hard for me to understand or I'm thinking too hard. I got this from this website: https://msdn.microsoft.com/en-us/library/dd647619.aspx
So from my understanding, shrink to fit discards the memory that are not used?
 

Onemic

Member
You could try listing what classes you've taken in college. I would also try for an internship before trying to apply for a full-time job

I have no idea where to find listings for internships. Any help here would be very appreciated.

I'm mainly using indeed.com and Monster to find stuff. Indeed has been pretty great with programmer listings, as there's usually at least two new listings a day, but of course, no internships.
 

tokkun

Member
Code:
size_type capacity( ) const;

What's size_type? Is it some kind of data type? What statements allows me to make sure that I return the amount of elements that the vector contains without allocating more storage/memory?

size_type is a data type. It's usually a 32-bit unsigned integer or a 64-bit unsigned integer, but it is implementation specific. It's defined as being a data type that is large enough to express the maximum size of the container.

The method you are looking for is size(), not capacity(). There is a difference between the two, and it has to do with your next question.

Code:
void shrink_to_fit(
);

I'm not sure if this is hard for me to understand or I'm thinking too hard. I got this from this website: https://msdn.microsoft.com/en-us/library/dd647619.aspx
So from my understanding, shrink to fit discards the memory that are not used?

Imagine that you have a vector that has reserved enough memory to store 8 items, and you are storing 8 items in it. Then size() = capacity() = 8.

You call pop_back() twice to remove two elements. Now size() = 6. However, chances are that capacity is still = 8 if the data is still stored in the same region of memory. If you call shrink_to_fit(), it will reduce the capacity to 6 (depending on implementation, this may involve creating a new memory region of size 6, copying the data from the old region, then freeing the old region).

Let me suggest that if you are not sure about how this works, there is a very good chance that you shouldn't be bothering with it. It is really only useful if you are working with very large vectors and you care a lot about memory footprint. Using shrink_to_fit can easily cause worse performance in your application if used haphazardly.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
I have no idea where to find listings for internships. Any help here would be very appreciated.

I'm mainly using indeed.com and Monster to find stuff. Indeed has been pretty great with programmer listings, as there's usually at least two new listings a day, but of course, no internships.

Ask people from your school.
 
I have no idea where to find listings for internships. Any help here would be very appreciated.

I'm mainly using indeed.com and Monster to find stuff. Indeed has been pretty great with programmer listings, as there's usually at least two new listings a day, but of course, no internships.

think of names of major companies that it would be cool to have an internship at. Then google "<company name> internship". For example:

Google
Microsoft
Facebook

And click on the first link on each of those pages.
 

Onemic

Member
Ask people from your school.

Will do. I actually have a co-op option for my course that I've already applied for, so hopefully I get in and get an almost guaranteed internship by next year. (I should get a response by next month)

think of names of major companies that it would be cool to have an internship at. Then google "<company name> internship". For example:

Google
Microsoft
Facebook

And click on the first link on each of those pages.

Thanks for this. Guess it's time to go Google hunting!
 

Slavik81

Member
Visual Studio Code doesn't support Intellisense for C++ btw, which makes it a deal killer for me. I'm still very excited for the future of Microsoft though, and being a Windows developer myself I'm loving all this open source stuff they're doing and embracing other platforms. I feel like it's only a matter of time before we see C++ support in VS Code. Here's to hoping anyway.
:(
 

BTW, I was slightly wrong. It "supports" it (note the quotation marks). It basically tokenizes your entire file, and when you hit Ctrl+Space, it displays a completion list with every token in your file. Still kind of worthless as far as I'm concerned, but not as bad as I thought initially.
 

hateradio

The Most Dangerous Yes Man
Docker is . . .


X6g8zyU.png



Alright, so I just wanted to test a simple Rails app to play with Docker, but I can't quite get things to work.

I already have a Rails app on my host pc, which I want to basically mount on the VM, then run it, and . . . that's it. Very simple.

Following this guide, I did this.

Code:
docker run -d -p 5000:3000 --name rails3 -v /c/Users/me/RubymineProjects/RailsSample:/docrails/guides/code/getting_started fcat/rails-getting-started

Note that I'm using a pre-built one, from a guide, "fcat/rails-getting-started" and trying to overlay my files onto the "getting_started" directory.

It's not working though.

This file system thing is quite confusing for now. I also tried mounting the VM's rails directory to my host PC, but then I can't override them because of some Unix User permissions. &#128549;
 

Joule

Member
I have no idea where to find listings for internships. Any help here would be very appreciated.

I'm mainly using indeed.com and Monster to find stuff. Indeed has been pretty great with programmer listings, as there's usually at least two new listings a day, but of course, no internships.

You should try taking a look at the job boards/postings of specific companies. For example IBM has a variety of student coop/internship positions
 
D

Deleted member 30609

Unconfirmed Member
It seems crazy to me that there isn't an IDE that just generates a header file for a given class and updates on the fly.

Maintaining two files that express the same information makes me feel like a cave-man.
 

Skittles

Member
Will do. I actually have a co-op option for my course that I've already applied for, so hopefully I get in and get an almost guaranteed internship by next year. (I should get a response by next month)



Thanks for this. Guess it's time to go Google hunting!
If not go to your school's career service office and ask them to get you started on applying for internships. Try to get it done before the fall semester starts though, nearly all internships recruit during the fall for summer internships. Also, unless the company is in town I'd ask your fellow programmers if they are applying for the same internship so you can car pool there
 
It seems crazy to me that there isn't an IDE that just generates a header file for a given class and updates on the fly.

Maintaining two files that express the same information makes me feel like a cave-man.

They don't express the same information though. The cpp file doesn't contain any information about base classes, member access specifiers, member variables, virtualness or staticness, default parameter values, whether something is a class or a struct, friend declarations, template definitions, and probably many other things I'm forgetting.

What you're asking for is essentially a different language, it's just not technically feasible for c++

Edit: also pure virtual functions and deleted functions
 

Moosichu

Member
Hi everyone, I'm having a bit of trouble with C++ and not in the actual coding side.

I've got a decent amount of experience in PHP and Java and mainly use Eclipse as my IDE. I have been slowly learning C++ but want to take the next step and play around with existing projects, the main problem being that I don't know how to get them properly set-up in an IDE. I've been trying to use Eclipes (in Ubuntu) but am happy to change to another one if recommended.

So basically, I've been trying to work out the correct sequence of steps so I can get this project: https://github.com/pyland/pyland , pulled off GitHub so I can start editing/building/debugging it in an IDE but keep getting stuck. I have managed to build it in the terminal using the provided instructions, but have no idea how to translate to IDE settings. Ideally I would for this project and work/commit to that to play around with. I've tried googling but nothing's worked so far and I don't really no where to begin.
 

Kansoku

Member
Ok, I'm having some problems here.
I'm using a bitset to represent (sub)sets of numbers (for example {3, 5}, a subset of {2, 3, 4, 5}, would be 1010, which I can turn into 10 and access a matrix at that position), and I need to iterate the possible combinations depending on two numbers. See:
Code:
n = 5, i = 0..4
when i = 0
from j = 1..4, put a number in a matrix[ j ][ 0 ]

when i = 1
from j = 1..4, put a number in a matrix at j and the int representation of the bit set with only 1 bit set to one, excluding the bit at j.
Example:
j = 1, bitset = 0010, 0100 and 1000
j = 2, bitset = 0001, 0100 and 1000
j = 3, bitset = 0001, 0010 and 1000
j = 4, bitset = 0001, 0010 and 0100

when i = 2
from j = 1..4, put a number in a matrix at j and the int representation of the bit set with only 2 bits set to one, excluding the bit at j.
Example:
j = 1, bitset = 0110, 1010 and 1100
j = 2, bitset = 0101, 1001 and 1100
j = 3, bitset = 0011, 1001 and 1010
j = 4, bitset = 0011, 0101 and 0110

and so on... (for every n < 100)

Basically, i is the numbers of bits that are set to 1 in the bitset and j is the bit that can't be 1, and I need to iterate trough them. When there's only one possible "arrangement" of the bitset is easy, but I have no idea how to iterate trough the possibilities when there's more than one. I thought to try shifting, but I can't seem to find a way to skip the bit that can't be changed (For example, if I shift 0011 to the left, I need it to be 1010 instead of 0110, because the third bit can't be one in this case).
 
Hi everyone, I'm having a bit of trouble with C++ and not in the actual coding side.

I've got a decent amount of experience in PHP and Java and mainly use Eclipse as my IDE. I have been slowly learning C++ but want to take the next step and play around with existing projects, the main problem being that I don't know how to get them properly set-up in an IDE. I've been trying to use Eclipes (in Ubuntu) but am happy to change to another one if recommended.

So basically, I've been trying to work out the correct sequence of steps so I can get this project: https://github.com/pyland/pyland , pulled off GitHub so I can start editing/building/debugging it in an IDE but keep getting stuck. I have managed to build it in the terminal using the provided instructions, but have no idea how to translate to IDE settings. Ideally I would for this project and work/commit to that to play around with. I've tried googling but nothing's worked so far and I don't really no where to begin.

I've never heard of anyone using Eclipse for C++. In Linux land people mostly use QtCreator for C++ if they use an IDE.

However, after looking at their Github it looks like a standard setup as long as your IDE knows where your Makefile is. All the commands before "make" are just environmental variables so check your IDE settings to configure those and you should be good to go.
 

Pegasus Actual

Gold Member
I've used NetBeans on windows to build linux C++ stuff remotely with mixed results. I wouldn't touch Eclipse for anything unless given no other choice. If all this latest Visual Studio linux-focused stuff works out it might make my life easier.
 
I've never heard of anyone using Eclipse for C++. In Linux land people mostly use QtCreator for C++ if they use an IDE.

However, after looking at their Github it looks like a standard setup as long as your IDE knows where your Makefile is. All the commands before "make" are just environmental variables so check your IDE settings to configure those and you should be good to go.
In the dark, pre-QtCreator days, Eclipse with the c++ plugin was one of the semi-viable choices for a linux IDE amid a field of rubbish.

IIRC I used code::blocks back then. It crashed all the time, but other than that it was moderately acceptable!
 
D

Deleted member 30609

Unconfirmed Member
They don't express the same information though. The cpp file doesn't contain any information about base classes, member access specifiers, member variables, virtualness or staticness, default parameter values, whether something is a class or a struct, friend declarations, template definitions, and probably many other things I'm forgetting.

What you're asking for is essentially a different language, it's just not technically feasible for c++

Edit: also pure virtual functions and deleted functions

I've calmed down a little after some teething, but there are still some inconsistencies that seem a bit off. For example, it seems you have to include function implementation for templated classes in the header file?
 

MiszMasz

Member
In the dark, pre-QtCreator days, Eclipse with the c++ plugin was one of the semi-viable choices for a linux IDE amid a field of rubbish.

IIRC I used code::blocks back then. It crashed all the time, but other than that it was moderately acceptable!

I use KDevelop most of the time for C++. If you don't like Qt Creator for whatever reason, i'd recommend it.
 

Moosichu

Member
I've never heard of anyone using Eclipse for C++. In Linux land people mostly use QtCreator for C++ if they use an IDE.

However, after looking at their Github it looks like a standard setup as long as your IDE knows where your Makefile is. All the commands before "make" are just environmental variables so check your IDE settings to configure those and you should be good to go.

I have. It's a little uncommon, but I knew a few people who used it at work.

I've used NetBeans on windows to build linux C++ stuff remotely with mixed results. I wouldn't touch Eclipse for anything unless given no other choice. If all this latest Visual Studio linux-focused stuff works out it might make my life easier.

I use KDevelop most of the time for C++. If you don't like Qt Creator for whatever reason, i'd recommend it.

Thank you! Will try Qt Creator out. Didn't know about all this stuff.
 

Moosichu

Member
Ok, so I have Qt Creator installed, created a new project, cloned from git, inserted the URL, it cloned succesfully.

But then I get the following error:
"Failed to open project in ".../pyland2"."

"Could not find any project files matching (CMakeLists.txt, *.creator, *.pro, *.qbs) in the directory ".../pyland2/src"."

And then I can't see it as a project? Any ideas on what to do?
 
I use KDevelop most of the time for C++. If you don't like Qt Creator for whatever reason, i'd recommend it.
I remember trying KDevelop back in the day, I didn't like it very much. But it has probably improved!

Pretty entrenched in QtCreator though, I won't switch away unless they really eff something up.

Ok, so I have Qt Creator installed, created a new project, cloned from git, inserted the URL, it cloned succesfully.

But then I get the following error:
"Failed to open project in ".../pyland2"."

"Could not find any project files matching (CMakeLists.txt, *.creator, *.pro, *.qbs) in the directory ".../pyland2/src"."

And then I can't see it as a project? Any ideas on what to do?
If the project is cmake'd: open the top-level CMakeLists.txt in QtCreator.

If there's just a makefile, you need to do a little more work.
 

Moosichu

Member
I remember trying KDevelop back in the day, I didn't like it very much. But it has probably improved!

Pretty entrenched in QtCreator though, I won't switch away unless they really eff something up.


If the project is cmake'd: open the top-level CMakeLists.txt in QtCreator.

If there's just a makefile, you need to do a little more work.

Got it to start building woot! However, a new issue has arisen! :(
Code:
/usr/include/boost/python/detail/wrap_python.hpp:50: error: pyconfig.h: No such file or directory
 # include <pyconfig.h>
Weirdly enought, it isn't just happening in the ide, when I tried to recompile the program in the terminal, the same issue arose even though it never has before. So something has changed on my machine. When I googled for this issue, most places say to do the following:

Code:
 install python-dev

But when I did it said it was all up to date, should I try removing and reinstalling it?

Doesn't matter I solved it. It was merely a problem with the environment variables :)
 

AAK

Member
Hi smart-GAF :)

I thankfully landed a summer job Which requires me to develop ios applications. I started reading up on objective c and noticed most tutorials are using Xcode on macs. I only have a PC, will I need to invest in a mac to start program in objective C to develop ios applications?

Thanks in advance!
 
Top Bottom