How do you mark a struct template as friend?

I have code like this:template <typename T, typename U> struct MyStruct { T aType; U anotherType;};class IWantToBeFriendsWithMyStruct{ friend struct MyStruct; //what is the correct syntax here ?};What is the correct syntax to give friendship to the template ? class IWantToBeFriendsWithMyStruct{ template <typename T, typename U> friend struct MyStruct;};Works in VS2008, and allows MyStruct to access the class. [XXX]According to this site, the correct syntax would beclass IWantToBeFriendsWithMyStruct{ template <typename T, typename U>...

I get the double free or corruption error , for my class functions

this is my .cpp file content:#include <iostream>#include"1.h"using namespace std;Stack:: Stack(){size=20; a=new int[size]; top=-1;}Stack::Stack (int si){size=si;a=new int[si];top =-1;}Stack::Stack(Stack& s){a=new int[s.size];for(int i=0 ; i<s.size; i++) a[i]=s.a[i];size=s.size;}Stack::~Stack(){delete [] a;}void Stack::Push(int data){if(this->isfull()) cout<<"stack is full!\n";else a[top++]=data;}int Stack::Pop(){if(this->isempty()) cout<<"stack is empty!\n";else return a[top--];}bool Stack::isempty(){if(top==-1) retur...

Trying to not swap with bubble sort if values are the same

i have my program working fine except for one minor problem that i can't seem to figure out. At the beginning, i want the user to input a sorting method, then enter values into an array of pointers until the user ends input with ^D. After the user ends input, my program prints the user input from highest to lowest based on the desired sort method. Again, i have everything working and sorting does happen, but what i want to do is print based on order of user input if two values of the sorting methods are the same. Here is my code, if any additional clarification is needed, j...

Why is the garbage location in the heap in C++ not designed as can be reallocated itself?

I'm learning heap and I am told if we have to reassign a pointer to a new address, we have to delete the content in the address of the heap that the pointer points to, or that content becomes garbage and may cause memory leak. Like:int* x = new int(10);//delete xx = new int(12) //without deleting x, the address that holds value 10 becomes garbage.Therefore I'm thinking although the language doesn't have a GC, why the language is not updated with making a non-pointed heap address be able to be reallocated itself? So when the address is reallocated, the garbage content can be...

Find two missing numbers

have a machine with O(1) memory.we want to pass n number (one by one) first time,and again we exclude two numbers and we will pass n-2 of them to machine.write an algorithm that finds missing numbers.This was an interview question and I couldn't solve it. It can be done with O(1) memory.You only need a few integers to keep track of some running sums. The integers do not require log n bits (where n is the number of input integers), they only require 2b+1 bits, where b is the number of bits in an individual input integer.When you first read the stream add all the numbers ...

rotating a vector using parametric equation of 3d circle

I'm not getting the required output i.e x2,y2,z2 in below code. Here the angle t is in degree, (x2,y2,z2) is the pint of vector face after being rotated and (a2,b2,c2) is the direction cosine of the rotated vector.I used rviz to visualize the rotating vector but its not comming as thought i.e its not rotating. double xgp[ipgp] = 23, ygp[ipgp] = 45, zgp[ipgp] = 345; int ipgp = 0; double a2, b2 , c2, a1, b1, c1 = ... double la = 0.0032; for(double t=0;t<360;t+=la) { double x2 = xgp[ipgp]+a2*cos(t)+a1*sin(t); double y2 = ygp[i...

Deoptimizing a program for the pipeline in Intel Sandybridge-family CPUs

I've been racking my brain for a week trying to complete this assignment and I'm hoping someone here can lead me toward the right path. Let me start with the instructor's instructions: Your assignment is the opposite of our first lab assignment, which was to optimize a prime number program. Your purpose in this assignment is to pessimize the program, i.e. make it run slower. Both of these are CPU-intensive programs. They take a few seconds to run on our lab PCs. You may not change the algorithm. To deoptimize the program, use your knowledge of how the Intel i7 pipeline ...

unordered_multimap - iterating the result of find() yields elements with different value

The multimap in C++ seems to work really odd, i would like to know why#include <iostream>#include <unordered_map>using namespace std;typedef unordered_multimap<char,int> MyMap;int main(int argc, char **argv){ MyMap map; map.insert(MyMap::value_type('a', 1)); map.insert(MyMap::value_type('b', 2)); map.insert(MyMap::value_type('c', 3)); map.insert(MyMap::value_type('d', 4)); map.insert(MyMap::value_type('a', 7)); map.insert(MyMap::value_type('b', 18)); for(auto it = map.begin(); it != map.end(); it++) { cout << it->fir...

glew problems (linking, crashing)

I am trying to set up glew in codeblocks (on Windows). I am linking it statically.The problem is there are two .lib files glew32.lib and glew32s.lib. When I link glew32.lib I´ve got undefined reference to ___glewGenBuffers (or any similar function except glewInit()). When I link glew32s.lib everything compiles fine but program crashes (segmentation fault) on line with glewInit(). Opengl context is created, #GLEW_STATIC is defined, glew downloaded from here. My testing program:#include <iostream>#define GLEW_STATIC#include <GL/glew.h>#include <GL/freeglut.h>...

Color picker that sends events per color pick

Does anyone know of any alternatives to the wxColourPicker included in wxWidgets 2.9.3? I was hoping for two things 1) that was non modal, 2) on to go in the wxPropertGrid When I had the need to extend wxColourPicker to support alpha channel I cannot find a replacement, so I wrote a C++/CLI wrapper for a C# color picker dialog.It may be a PITA at first, but you can extend your application faster when the wrapper is set up - at the cost of your application depending on the .NET framework.If you need a modeless color picker/editor in C#, look at http://www.codeproject.com/...

Autocompletion in Vim

In a nutshell, I'm searching for a working autocompletion feature for the Vim editor. I've argued before that Vim completely replaces an IDE under Linux and while that's certainly true, it lacks one important feature: autocompletion.I know about Ctrl+N, Exuberant Ctags integration, Taglist, cppcomplete and OmniCppComplete. Alas, none of these fits my description of “working autocompletion:”Ctrl+N works nicely (only) if you've forgotton how to spell class, or while. Oh well.Ctags gives you the rudiments but has a lot of drawbacks.Taglist is just a Ctags wrapper and as such, ...

C++ Iterating with for loop and calling a function within it

So I've been following some tutorials on Udemy for C++ and so far it's been incredibly informative and clear however I'm a little stumped by how a for function is calling another function.So my first function is;EDITI've included use namespace std so being the String rather than std::string getGuess(){ cout << "Enter your guess" << endl; Guess = ""; getLine(cin,Guess); cout << "Your guess was: " << Guess << endl; return Guess;}And then to iterate through this function 5 times so they can guess 5 times I'm writing void play(){ ...

Batch build does nothing in Visual Studio 2017

We've just migrated our IDE from Visual Studio 2010 to Visual Studio 2017, although projects are going to be kept with VS 2010's toolset for a time (lot of external dependencies not compatible with 2017 yet). All are C++ projects.My current problem is that the Batch build is doing nothing: I launch it, select all the projects and none of the three options (Build, Rebuild, Clean) does anything.Any idea how to fix it? Maybe it is just a bug of VS 2017?Visual Studio 2017 version: 15.2 (26430.6), no newer updates availableOutput window after executing the batch build: ========...

C++ class initialisation containing class variable initialization

I noticed some code of a colleague today that initialized class variables in the initialization. However it was causing a warning, he says because of the order they are in. My question is why is it better to do variable initialization where it currently is and not within the curly brackets?DiagramScene::DiagramScene( int slideNo, QRectF screenRect, MainWindow* parent ) : QGraphicsScene( screenRect, parent ), myParent( parent ), slideUndoImageCurrentIndex(-1), nextGroupID(0), m_undoInProgress(false), m_deleteItemOnNextUndo(0) line(0), path(0){ /...

is there a way to skip class name while define a class member function in c++?

for example, I declare a class named Dog in the dog.h:class Dog {public: void bark();private: int count;}Is there any way that I could just write the following code in the dog.cpp:void bark() { printf("count: %d", count);}instead of:void Dog::bark() { printf("count: %d", count);}It will help saving time if I got a ton of class functions which should be defined. (I can just copy-paste the function definition to .h file without the routine to delete class name every time.)in the objective-c code, I can add a "@implementation ... @end" scope in the .m(its role is lik...

xcode c++ error: allocating an object of abstract class type 'Grain'

This is the method in which the error occurs.The goal here is to generate a certain number of sand grains based on a model grain (modele), for a given small increment of time dt. Grain is an abstract class because it hase purely virtual methods and it has to be that way.The problem appears on for(size_t a(0); a<vect.size(); ++a){ vect[a] = new Grain(*modele);}without this initializing loop, the vector returns all same grains but I need them to be slightly different (the Aleatoire class provides the necessary tool for that).For example if I dofor(size_t a(0); a<vect...

Page 1 of 1003  |  Show More Pages:  Top Prev Next Last